Fixes for line items (#3028)

This commit is contained in:
David Bomba 2019-10-29 22:12:59 +11:00 committed by GitHub
parent 004d39cc73
commit 13e104c1d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 26 deletions

View File

@ -63,7 +63,7 @@ class InvoiceItemSum
public function process() public function process()
{ {
if(!$this->invoice->line_items || count($this->invoice->line_items) == 0){ if(!$this->invoice->line_items || !isset($this->invoice->line_items) || count($this->invoice->line_items) == 0){
$this->items = []; $this->items = [];
return $this; return $this;
} }

View File

@ -65,6 +65,7 @@ class InvoiceSum
public function build() public function build()
{ {
$this->calculateLineItems() $this->calculateLineItems()
->calculateDiscount() ->calculateDiscount()
->calculateCustomValues() ->calculateCustomValues()
@ -99,17 +100,17 @@ class InvoiceSum
private function calculateCustomValues() private function calculateCustomValues()
{ {
$this->total_taxes += $this->valuerTax($this->invoice->custom_value1, $this->invoice->custom_surcharge_taxes1); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
$this->total_custom_values += $this->valuer($this->invoice->custom_value1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value2, $this->invoice->custom_surcharge_taxes2); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_custom_values += $this->valuer($this->invoice->custom_value2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value3, $this->invoice->custom_surcharge_taxes3); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_custom_values += $this->valuer($this->invoice->custom_value3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value4, $this->invoice->custom_surcharge_taxes4); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4);
$this->total_custom_values += $this->valuer($this->invoice->custom_value4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4);
$this->total += $this->total_custom_values; $this->total += $this->total_custom_values;

View File

@ -100,17 +100,17 @@ class InvoiceSumInclusive
private function calculateCustomValues() private function calculateCustomValues()
{ {
$this->total_taxes += $this->valuerTax($this->invoice->custom_value1, $this->invoice->custom_surcharge_taxes1); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge1, $this->invoice->custom_surcharge_taxes1);
$this->total_custom_values += $this->valuer($this->invoice->custom_value1); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value2, $this->invoice->custom_surcharge_taxes2); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge2, $this->invoice->custom_surcharge_taxes2);
$this->total_custom_values += $this->valuer($this->invoice->custom_value2); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge2);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value3, $this->invoice->custom_surcharge_taxes3); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge3, $this->invoice->custom_surcharge_taxes3);
$this->total_custom_values += $this->valuer($this->invoice->custom_value3); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge3);
$this->total_taxes += $this->valuerTax($this->invoice->custom_value4, $this->invoice->custom_surcharge_taxes4); $this->total_taxes += $this->valuerTax($this->invoice->custom_surcharge4, $this->invoice->custom_surcharge_taxes4);
$this->total_custom_values += $this->valuer($this->invoice->custom_value4); $this->total_custom_values += $this->valuer($this->invoice->custom_surcharge4);
$this->total += $this->total_custom_values; $this->total += $this->total_custom_values;

View File

@ -39,6 +39,10 @@
* @OA\Property(property="last_viewed", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="last_viewed", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="updated_at", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"), * @OA\Property(property="archived_at", type="number", format="integer", example="1434342123", description="Timestamp"),
* @OA\Property(property="custom_surcharge1", type="number", format="float", example="10.00", description="First Custom Surcharge"),
* @OA\Property(property="custom_surcharge2", type="number", format="float", example="10.00", description="Second Custom Surcharge"),
* @OA\Property(property="custom_surcharge3", type="number", format="float", example="10.00", description="Third Custom Surcharge"),
* @OA\Property(property="custom_surcharge4", type="number", format="float", example="10.00", description="Fourth Custom Surcharge"),
* @OA\Property(property="custom_surcharge_taxes", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"), * @OA\Property(property="custom_surcharge_taxes", type="boolean", example=true, description="Toggles charging taxes on custom surcharge amounts"),
* ) * )
*/ */

View File

@ -34,7 +34,6 @@ class StoreInvoiceRequest extends Request
public function rules() public function rules()
{ {
$this->sanitize(); $this->sanitize();
return [ return [
'client_id' => 'required', 'client_id' => 'required',
// 'invoice_type_id' => 'integer', // 'invoice_type_id' => 'integer',
@ -47,8 +46,8 @@ class StoreInvoiceRequest extends Request
$input = $this->all(); $input = $this->all();
$input['client_id'] = $this->decodePrimaryKey($input['client_id']); $input['client_id'] = $this->decodePrimaryKey($input['client_id']);
$input['line_items'] = isset($input['line_items']) ?: []; $input['line_items'] = isset($input['line_items']) ? $input['line_items'] : [];
//$input['line_items'] = json_encode($input['line_items']);
$this->replace($input); $this->replace($input);
return $this->all(); return $this->all();

View File

@ -57,7 +57,6 @@ class InvoiceRepository extends BaseRepository
$starting_amount = $invoice->amount; $starting_amount = $invoice->amount;
$invoice->fill($data); $invoice->fill($data);
$invoice->save(); $invoice->save();
if(isset($data['client_contacts'])) if(isset($data['client_contacts']))

View File

@ -116,12 +116,12 @@ class InvoiceTransformer extends EntityTransformer
'custom_value4' => (string) $invoice->custom_value4 ?: '', 'custom_value4' => (string) $invoice->custom_value4 ?: '',
'has_tasks' => (bool) $invoice->has_tasks, 'has_tasks' => (bool) $invoice->has_tasks,
'has_expenses' => (bool) $invoice->has_expenses, 'has_expenses' => (bool) $invoice->has_expenses,
'custom_surcharge1' => $invoice->custom_surcharge1 ?: '', 'custom_surcharge1' => (float)$invoice->custom_surcharge1,
'custom_surcharge2' => $invoice->custom_surcharge2 ?: '', 'custom_surcharge2' => (float)$invoice->custom_surcharge2,
'custom_surcharge3' => $invoice->custom_surcharge3 ?: '', 'custom_surcharge3' => (float)$invoice->custom_surcharge3,
'custom_surcharge4' => $invoice->custom_surcharge4 ?: '', 'custom_surcharge4' => (float)$invoice->custom_surcharge4,
'custom_surcharge_taxes' => (bool) $invoice->custom_surcharge_taxes, 'custom_surcharge_taxes' => (bool) $invoice->custom_surcharge_taxes,
'line_items' => $invoice->line_items ?: '', 'line_items' => $invoice->line_items ?: (array)[],
'backup' => $invoice->backup ?: '', 'backup' => $invoice->backup ?: '',
'settings' => $invoice->settings ?: '', 'settings' => $invoice->settings ?: '',