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

View File

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

View File

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

View File

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