set status as draft and removed payments #94

This commit is contained in:
denisdulici 2017-11-26 19:45:49 +03:00
parent e227c1d8ff
commit 5e923024c2
4 changed files with 54 additions and 38 deletions

View File

@ -201,55 +201,51 @@ class Bills extends Controller
$bill->update($request->input()); $bill->update($request->input());
// Added bill total sub total // Added bill total sub total
$bill_sub_total = [ BillTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'bill_id' => $bill->id, 'bill_id' => $bill->id,
'code' => 'sub_total', 'code' => 'sub_total',
'name' => 'bills.sub_total', 'name' => 'bills.sub_total',
'amount' => $sub_total, 'amount' => $sub_total,
'sort_order' => 1, 'sort_order' => 1,
]; ]);
BillTotal::create($bill_sub_total);
$sort_order = 2; $sort_order = 2;
// Added bill total taxes // Added bill total taxes
if ($taxes) { if ($taxes) {
foreach ($taxes as $tax) { foreach ($taxes as $tax) {
$bill_tax_total = [ BillTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'bill_id' => $bill->id, 'bill_id' => $bill->id,
'code' => 'tax', 'code' => 'tax',
'name' => $tax['name'], 'name' => $tax['name'],
'amount' => $tax['amount'], 'amount' => $tax['amount'],
'sort_order' => $sort_order, 'sort_order' => $sort_order,
]; ]);
BillTotal::create($bill_tax_total);
$sort_order++; $sort_order++;
} }
} }
// Added bill total total // Added bill total total
$bill_total = [ BillTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'bill_id' => $bill->id, 'bill_id' => $bill->id,
'code' => 'total', 'code' => 'total',
'name' => 'bills.total', 'name' => 'bills.total',
'amount' => $sub_total + $tax_total, 'amount' => $sub_total + $tax_total,
'sort_order' => $sort_order, 'sort_order' => $sort_order,
]; ]);
BillTotal::create($bill_total); // Add bill history
BillHistory::create([
$request['bill_id'] = $bill->id; 'company_id' => session('company_id'),
$request['status_code'] = 'new'; 'bill_id' => $bill->id,
$request['notify'] = 0; 'status_code' => 'draft',
$request['description'] = trans('messages.success.added', ['type' => $request['bill_number']]); 'notify' => 0,
'description' => trans('messages.success.added', ['type' => $bill->bill_number]),
BillHistory::create($request->input()); ]);
// Fire the event to make it extendible // Fire the event to make it extendible
event(new BillCreated($bill)); event(new BillCreated($bill));
@ -272,6 +268,15 @@ class Bills extends Controller
{ {
$clone = $bill->duplicate(); $clone = $bill->duplicate();
// Add bill history
BillHistory::create([
'company_id' => session('company_id'),
'bill_id' => $clone->id,
'status_code' => 'draft',
'notify' => 0,
'description' => trans('messages.success.added', ['type' => $clone->bill_number]),
]);
$message = trans('messages.success.duplicated', ['type' => trans_choice('general.bills', 1)]); $message = trans('messages.success.duplicated', ['type' => trans_choice('general.bills', 1)]);
flash($message)->success(); flash($message)->success();

View File

@ -224,12 +224,14 @@ class Invoices extends Controller
// Add invoice totals // Add invoice totals
$this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total); $this->addTotals($invoice, $request, $taxes, $sub_total, $tax_total);
$request['invoice_id'] = $invoice->id; // Add invoice history
$request['status_code'] = 'draft'; InvoiceHistory::create([
$request['notify'] = 0; 'company_id' => session('company_id'),
$request['description'] = trans('messages.success.added', ['type' => $request['invoice_number']]); 'invoice_id' => $invoice->id,
'status_code' => 'draft',
InvoiceHistory::create($request->all()); 'notify' => 0,
'description' => trans('messages.success.added', ['type' => $invoice->invoice_number]),
]);
// Update next invoice number // Update next invoice number
$this->increaseNextInvoiceNumber(); $this->increaseNextInvoiceNumber();
@ -255,6 +257,15 @@ class Invoices extends Controller
{ {
$clone = $invoice->duplicate(); $clone = $invoice->duplicate();
// Add invoice history
InvoiceHistory::create([
'company_id' => session('company_id'),
'invoice_id' => $clone->id,
'status_code' => 'draft',
'notify' => 0,
'description' => trans('messages.success.added', ['type' => $clone->invoice_number]),
]);
// Update next invoice number // Update next invoice number
$this->increaseNextInvoiceNumber(); $this->increaseNextInvoiceNumber();
@ -669,47 +680,41 @@ class Invoices extends Controller
$sort_order = 1; $sort_order = 1;
// Added invoice total sub total // Added invoice total sub total
$invoice_sub_total = [ InvoiceTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'code' => 'sub_total', 'code' => 'sub_total',
'name' => 'invoices.sub_total', 'name' => 'invoices.sub_total',
'amount' => $sub_total, 'amount' => $sub_total,
'sort_order' => $sort_order, 'sort_order' => $sort_order,
]; ]);
InvoiceTotal::create($invoice_sub_total);
$sort_order++; $sort_order++;
// Added invoice total taxes // Added invoice total taxes
if ($taxes) { if ($taxes) {
foreach ($taxes as $tax) { foreach ($taxes as $tax) {
$invoice_tax_total = [ InvoiceTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'code' => 'tax', 'code' => 'tax',
'name' => $tax['name'], 'name' => $tax['name'],
'amount' => $tax['amount'], 'amount' => $tax['amount'],
'sort_order' => $sort_order, 'sort_order' => $sort_order,
]; ]);
InvoiceTotal::create($invoice_tax_total);
$sort_order++; $sort_order++;
} }
} }
// Added invoice total total // Added invoice total total
$invoice_total = [ InvoiceTotal::create([
'company_id' => $request['company_id'], 'company_id' => $request['company_id'],
'invoice_id' => $invoice->id, 'invoice_id' => $invoice->id,
'code' => 'total', 'code' => 'total',
'name' => 'invoices.total', 'name' => 'invoices.total',
'amount' => $sub_total + $tax_total, 'amount' => $sub_total + $tax_total,
'sort_order' => $sort_order, 'sort_order' => $sort_order,
]; ]);
InvoiceTotal::create($invoice_total);
} }
} }

View File

@ -50,7 +50,7 @@ class Bill extends Model
* *
* @var array * @var array
*/ */
protected $cloneable_relations = ['histories', 'items', 'payments', 'totals']; protected $cloneable_relations = ['items', 'totals'];
public function vendor() public function vendor()
{ {
@ -102,6 +102,11 @@ class Bill extends Model
return $query->where('bill_status_code', '!=', 'new'); return $query->where('bill_status_code', '!=', 'new');
} }
public function onCloning($src, $child = null)
{
$this->bill_status_code = 'draft';
}
/** /**
* Convert amount to double. * Convert amount to double.
* *

View File

@ -51,7 +51,7 @@ class Invoice extends Model
* *
* @var array * @var array
*/ */
protected $cloneable_relations = ['histories', 'items', 'payments', 'totals']; protected $cloneable_relations = ['items', 'totals'];
public function user() public function user()
{ {
@ -110,6 +110,7 @@ class Invoice extends Model
public function onCloning($src, $child = null) public function onCloning($src, $child = null)
{ {
$this->invoice_status_code = 'draft';
$this->invoice_number = $this->getNextInvoiceNumber(); $this->invoice_number = $this->getNextInvoiceNumber();
} }