Merge branch '1.3-dev' of github.com:akaunting/akaunting into 1.3-dev
This commit is contained in:
commit
2593da7a2b
@ -30,12 +30,13 @@ class Transactions extends Controller
|
||||
|
||||
$types = collect(['expense' => 'Expense', 'income' => 'Income'])
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.types', 2)]), '');
|
||||
|
||||
$categories = collect(Category::enabled()->type('income')->pluck('name', 'id'))
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
|
||||
|
||||
$type = $request->get('type');
|
||||
|
||||
$type_cats = empty($type) ? ['income', 'expense'] : $type;
|
||||
$categories = collect(Category::enabled()->type($type_cats)->pluck('name', 'id'))
|
||||
->prepend(trans('general.all_type', ['type' => trans_choice('general.categories', 2)]), '');
|
||||
|
||||
if ($type != 'income') {
|
||||
$this->addTransactions(Payment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1));
|
||||
$this->addTransactions(BillPayment::collect(['paid_at'=> 'desc']), trans_choice('general.expenses', 1), trans_choice('general.bills', 1));
|
||||
|
@ -323,44 +323,31 @@ class Items extends Controller
|
||||
$price = (double) $item['price'];
|
||||
$quantity = (double) $item['quantity'];
|
||||
|
||||
$item_tax_total= 0;
|
||||
$item_tax_total = 0;
|
||||
$item_sub_total = ($price * $quantity);
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax = Tax::find($tax_id);
|
||||
|
||||
$item_tax_total = (($price * $quantity) / 100) * $tax->rate;
|
||||
$item_tax = (($price * $quantity) / 100) * $tax->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$item_tax = $item_tax - ($item_tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$item_tax_total += $item_tax;
|
||||
}
|
||||
}
|
||||
|
||||
$sub_total += $item_sub_total;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$item_tax_total = $item_tax_total - ($item_tax_total * ($discount / 100));
|
||||
}
|
||||
|
||||
$tax_total += $item_tax_total;
|
||||
|
||||
$items[$key] = money($item_sub_total, $currency_code, true)->format();
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $tax_row => $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
|
||||
$taxes['multiple-tax-' . $tax_row . '-total'] = money($multiple_tax_amount, $currency_code, true)->format();
|
||||
}
|
||||
}
|
||||
|
||||
$json->items = $items;
|
||||
|
||||
$json->sub_total = money($sub_total, $currency_code, true)->format();
|
||||
@ -378,32 +365,10 @@ class Items extends Controller
|
||||
$sub_total = $sub_total - ($sub_total * ($discount / 100));
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $tax_row => $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
|
||||
$taxes['multiple-tax-' . $tax_row . '-total'] = money($multiple_tax_amount, $currency_code, true)->format();
|
||||
}
|
||||
}
|
||||
|
||||
$grand_total = $sub_total + $tax_total;
|
||||
|
||||
$json->grand_total = money($grand_total, $currency_code, true)->format();
|
||||
|
||||
$json->multible_taxes = false;
|
||||
|
||||
if (!empty($taxes)) {
|
||||
$json->multible_taxes = $taxes;
|
||||
}
|
||||
|
||||
// Get currency object
|
||||
$currency = Currency::where('code', $currency_code)->first();
|
||||
|
||||
|
@ -169,7 +169,6 @@ class Bills extends Controller
|
||||
|
||||
if ($request['item']) {
|
||||
foreach ($request['item'] as $item) {
|
||||
unset($tax_object);
|
||||
$item_sku = '';
|
||||
|
||||
if (!empty($item['item_id'])) {
|
||||
@ -183,18 +182,32 @@ class Bills extends Controller
|
||||
$item_object->save();
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$bill_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$bill_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'bill_id' => $bill->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,53 +216,33 @@ class Bills extends Controller
|
||||
$bill_item['sku'] = $item_sku;
|
||||
$bill_item['quantity'] = (double) $item['quantity'];
|
||||
$bill_item['price'] = (double) $item['price'];
|
||||
$bill_item['tax'] = $tax;
|
||||
$bill_item['tax_id'] = $tax_id;
|
||||
$bill_item['tax'] = $item_tax;
|
||||
$bill_item['tax_id'] = 0;//$tax_id;
|
||||
$bill_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
BillItem::create($bill_item);
|
||||
$bill_item_created = BillItem::create($bill_item);
|
||||
|
||||
// Set taxes
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
if ($bill_item_taxes) {
|
||||
foreach ($bill_item_taxes as $bill_item_tax) {
|
||||
$bill_item_tax['invoice_item_id'] = $bill_item_created->id;
|
||||
|
||||
BillItemTax::create($bill_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($bill_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$bill_item_tax['tax_id']]['amount'] += $bill_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$bill_item_tax['tax_id']] = [
|
||||
'name' => $bill_item_tax['name'],
|
||||
'amount' => $bill_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate totals
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $bill_item['total'];
|
||||
|
||||
unset($tax_object);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,30 +255,6 @@ class Bills extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -422,6 +391,7 @@ class Bills extends Controller
|
||||
public function update(Bill $bill, Request $request)
|
||||
{
|
||||
$taxes = [];
|
||||
|
||||
$tax_total = 0;
|
||||
$sub_total = 0;
|
||||
$discount_total = 0;
|
||||
@ -445,18 +415,32 @@ class Bills extends Controller
|
||||
$item_sku = $item_object->sku;
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$bill_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$bill_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'bill_id' => $bill->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -465,49 +449,32 @@ class Bills extends Controller
|
||||
$bill_item['sku'] = $item_sku;
|
||||
$bill_item['quantity'] = (double) $item['quantity'];
|
||||
$bill_item['price'] = (double) $item['price'];
|
||||
$bill_item['tax'] = $tax;
|
||||
$bill_item['tax_id'] = $tax_id;
|
||||
$bill_item['tax'] = $item_tax;
|
||||
$bill_item['tax_id'] = 0;//$tax_id;
|
||||
$bill_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $bill_item['total'];
|
||||
|
||||
BillItem::create($bill_item);
|
||||
}
|
||||
}
|
||||
$bill_item_created = BillItem::create($bill_item);
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
if ($bill_item_taxes) {
|
||||
foreach ($bill_item_taxes as $bill_item_tax) {
|
||||
$bill_item_tax['invoice_item_id'] = $bill_item_created->id;
|
||||
|
||||
BillItemTax::create($bill_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($bill_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$bill_item_tax['tax_id']]['amount'] += $bill_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$bill_item_tax['tax_id']] = [
|
||||
'name' => $bill_item_tax['name'],
|
||||
'amount' => $bill_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -520,30 +487,6 @@ class Bills extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -892,21 +835,6 @@ class Bills extends Controller
|
||||
{
|
||||
$sort_order = 1;
|
||||
|
||||
if (isset($taxes['GST'])) {
|
||||
foreach ($taxes['GST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'gst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added bill sub total
|
||||
BillTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
@ -936,24 +864,9 @@ class Bills extends Controller
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (isset($taxes['PST'])) {
|
||||
foreach ($taxes['PST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'pst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added bill taxes
|
||||
if (isset($taxes['VAT'])) {
|
||||
foreach ($taxes['VAT'] as $tax) {
|
||||
if (isset($taxes)) {
|
||||
foreach ($taxes as $tax) {
|
||||
BillTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'bill_id' => $bill->id,
|
||||
|
@ -14,6 +14,7 @@ use App\Models\Income\Customer;
|
||||
use App\Models\Income\Invoice;
|
||||
use App\Models\Income\InvoiceHistory;
|
||||
use App\Models\Income\InvoiceItem;
|
||||
use App\Models\Income\InvoiceItemTax;
|
||||
use App\Models\Income\InvoiceTotal;
|
||||
use App\Models\Income\InvoicePayment;
|
||||
use App\Models\Income\InvoiceStatus;
|
||||
@ -218,18 +219,32 @@ class Invoices extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$invoice_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$invoice_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,53 +253,33 @@ class Invoices extends Controller
|
||||
$invoice_item['sku'] = $item_sku;
|
||||
$invoice_item['quantity'] = (double) $item['quantity'];
|
||||
$invoice_item['price'] = (double) $item['price'];
|
||||
$invoice_item['tax'] = $tax;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['tax'] = $item_tax;
|
||||
$invoice_item['tax_id'] = 0;//(int) $item_taxes;
|
||||
$invoice_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
$invoice_item_created = InvoiceItem::create($invoice_item);
|
||||
|
||||
// Set taxes
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
if ($invoice_item_taxes) {
|
||||
foreach ($invoice_item_taxes as $invoice_item_tax) {
|
||||
$invoice_item_tax['invoice_item_id'] = $invoice_item_created->id;
|
||||
|
||||
InvoiceItemTax::create($invoice_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($invoice_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$invoice_item_tax['tax_id']]['amount'] += $invoice_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$invoice_item_tax['tax_id']] = [
|
||||
'name' => $invoice_item_tax['name'],
|
||||
'amount' => $invoice_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate totals
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $invoice_item['total'];
|
||||
|
||||
unset($tax_object);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -297,30 +292,6 @@ class Invoices extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -463,6 +434,7 @@ class Invoices extends Controller
|
||||
public function update(Invoice $invoice, Request $request)
|
||||
{
|
||||
$taxes = [];
|
||||
|
||||
$tax_total = 0;
|
||||
$sub_total = 0;
|
||||
$discount_total = 0;
|
||||
@ -486,18 +458,32 @@ class Invoices extends Controller
|
||||
$item_sku = $item_object->sku;
|
||||
}
|
||||
|
||||
$tax = $tax_id = 0;
|
||||
$item_tax = 0;
|
||||
$item_taxes = [];
|
||||
$invoice_item_taxes = [];
|
||||
|
||||
if (!empty($item['tax_id'])) {
|
||||
$tax_object = Tax::find($item['tax_id']);
|
||||
foreach ($item['tax_id'] as $tax_id) {
|
||||
$tax_object = Tax::find($tax_id);
|
||||
|
||||
$tax_id = $item['tax_id'];
|
||||
$item_taxes[] = $tax_id;
|
||||
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
$tax = (((double) $item['price'] * (double) $item['quantity']) / 100) * $tax_object->rate;
|
||||
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
// Apply discount to tax
|
||||
if ($discount) {
|
||||
$tax = $tax - ($tax * ($discount / 100));
|
||||
}
|
||||
|
||||
$invoice_item_taxes[] = [
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'tax_id' => $tax_id,
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax,
|
||||
];
|
||||
|
||||
$item_tax += $tax;
|
||||
}
|
||||
}
|
||||
|
||||
@ -507,48 +493,31 @@ class Invoices extends Controller
|
||||
$invoice_item['quantity'] = (double) $item['quantity'];
|
||||
$invoice_item['price'] = (double) $item['price'];
|
||||
$invoice_item['tax'] = $tax;
|
||||
$invoice_item['tax_id'] = $tax_id;
|
||||
$invoice_item['tax_id'] = 0;//$tax_id;
|
||||
$invoice_item['total'] = (double) $item['price'] * (double) $item['quantity'];
|
||||
|
||||
if (isset($tax_object)) {
|
||||
if (isset($taxes['VAT']) && array_key_exists($tax_object->id, $taxes['VAT'])) {
|
||||
$taxes['VAT'][$tax_object->id]['amount'] += $tax;
|
||||
} else {
|
||||
$taxes['VAT'][$tax_object->id] = [
|
||||
'name' => $tax_object->name,
|
||||
'amount' => $tax
|
||||
];
|
||||
$invoice_item_created = InvoiceItem::create($invoice_item);
|
||||
|
||||
if ($invoice_item_taxes) {
|
||||
foreach ($invoice_item_taxes as $invoice_item_tax) {
|
||||
$invoice_item_tax['invoice_item_id'] = $invoice_item_created->id;
|
||||
|
||||
InvoiceItemTax::create($invoice_item_tax);
|
||||
|
||||
// Set taxes
|
||||
if (isset($taxes) && array_key_exists($invoice_item_tax['tax_id'], $taxes)) {
|
||||
$taxes[$invoice_item_tax['tax_id']]['amount'] += $invoice_item_tax['amount'];
|
||||
} else {
|
||||
$taxes[$invoice_item_tax['tax_id']] = [
|
||||
'name' => $invoice_item_tax['name'],
|
||||
'amount' => $invoice_item_tax['amount']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tax_total += $tax;
|
||||
$tax_total += $item_tax;
|
||||
$sub_total += $invoice_item['total'];
|
||||
|
||||
InvoiceItem::create($invoice_item);
|
||||
}
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'GST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($sub_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['GST']) && array_key_exists($multible_tax_object->id, $taxes['GST'])) {
|
||||
$taxes['GST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['GST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$sub_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
@ -561,30 +530,6 @@ class Invoices extends Controller
|
||||
$s_total = $s_total - $s_discount;
|
||||
}
|
||||
|
||||
if ($request['multiple_tax']) {
|
||||
foreach ($request['multiple_tax'] as $multiple_tax) {
|
||||
if ($multiple_tax['position'] != 'PST') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$multible_tax_object = Tax::find($multiple_tax['tax_id']);
|
||||
|
||||
$multiple_tax_amount = ($s_total / 100) * $multible_tax_object->rate;
|
||||
|
||||
if (isset($taxes['PST']) && array_key_exists($multible_tax_object->id, $taxes['PST'])) {
|
||||
$taxes['PST'][$multible_tax_object->id]['amount'] += $multiple_tax_amount;
|
||||
} else {
|
||||
$taxes['PST'][$multible_tax_object->id] = [
|
||||
'id' => $multible_tax_object->id,
|
||||
'name' => $multible_tax_object->name,
|
||||
'amount' => $multiple_tax_amount
|
||||
];
|
||||
}
|
||||
|
||||
$tax_total += $multiple_tax_amount;
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $s_total + $tax_total;
|
||||
|
||||
$request['amount'] = money($amount, $request['currency_code'])->getAmount();
|
||||
@ -1049,21 +994,6 @@ class Invoices extends Controller
|
||||
{
|
||||
$sort_order = 1;
|
||||
|
||||
if (isset($taxes['GST'])) {
|
||||
foreach ($taxes['GST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'gst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added invoice sub total
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
@ -1093,24 +1023,9 @@ class Invoices extends Controller
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (isset($taxes['PST'])) {
|
||||
foreach ($taxes['PST'] as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
'code' => 'pst-' . $tax['id'],
|
||||
'name' => $tax['name'],
|
||||
'amount' => $tax['amount'],
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
}
|
||||
|
||||
// Added invoice taxes
|
||||
if (isset($taxes['VAT'])) {
|
||||
foreach ($taxes['VAT'] as $tax) {
|
||||
if (isset($taxes)) {
|
||||
foreach ($taxes as $tax) {
|
||||
InvoiceTotal::create([
|
||||
'company_id' => $request['company_id'],
|
||||
'invoice_id' => $invoice->id,
|
||||
|
63
app/Http/Controllers/Modals/Taxes.php
Normal file
63
app/Http/Controllers/Modals/Taxes.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Modals;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Setting\Tax as Request;
|
||||
use App\Models\Setting\Tax;
|
||||
|
||||
class Taxes extends Controller
|
||||
{
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Add CRUD permission check
|
||||
$this->middleware('permission:create-settings-taxes')->only(['create', 'store']);
|
||||
$this->middleware('permission:read-settings-taxes')->only(['index', 'edit']);
|
||||
$this->middleware('permission:update-settings-taxes')->only(['update', 'enable', 'disable']);
|
||||
$this->middleware('permission:delete-settings-taxes')->only('destroy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$html = view('modals.taxes.create')->render();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'message' => 'null',
|
||||
'html' => $html,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request['enabled'] = 1;
|
||||
|
||||
$tax = Tax::create($request->all());
|
||||
|
||||
$message = trans('messages.success.added', ['type' => trans_choice('general.taxes', 1)]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'error' => false,
|
||||
'data' => $tax,
|
||||
'message' => $message,
|
||||
'html' => 'null',
|
||||
]);
|
||||
}
|
||||
}
|
@ -82,6 +82,11 @@ class Bill extends Model
|
||||
return $this->hasMany('App\Models\Expense\BillItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
|
@ -29,6 +29,11 @@ class BillItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax', 'bill_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
@ -66,4 +71,23 @@ class BillItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
47
app/Models/Expense/BillItemTax.php
Normal file
47
app/Models/Expense/BillItemTax.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class BillItemTax extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'bill_item_taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'bill_item_id', 'tax_id', 'name', 'amount'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert amount to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAmountAttribute($value)
|
||||
{
|
||||
$this->attributes['amount'] = (double) $value;
|
||||
}
|
||||
}
|
@ -83,6 +83,11 @@ class Invoice extends Model
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceHistory');
|
||||
|
@ -29,6 +29,11 @@ class InvoiceItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax', 'invoice_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
@ -66,4 +71,23 @@ class InvoiceItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
47
app/Models/Income/InvoiceItemTax.php
Normal file
47
app/Models/Income/InvoiceItemTax.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class InvoiceItemTax extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'invoice_item_taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'invoice_item_id', 'tax_id', 'name', 'amount'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert amount to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAmountAttribute($value)
|
||||
{
|
||||
$this->attributes['amount'] = (double) $value;
|
||||
}
|
||||
}
|
@ -56,7 +56,7 @@ class Category extends Model
|
||||
*/
|
||||
public function scopeType($query, $type)
|
||||
{
|
||||
return $query->where('type', $type);
|
||||
return $query->whereIn('type', (array) $type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateBillItemTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('bill_item_taxes', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('company_id');
|
||||
$table->integer('bill_id');
|
||||
$table->integer('bill_item_id');
|
||||
$table->integer('tax_id');
|
||||
$table->string('name');
|
||||
$table->double('amount', 15, 4)->default('0.0000');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('company_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('bill_item_taxes');
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
class CreateInvoiceItemTaxesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('invoice_item_taxes', function (Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('company_id');
|
||||
$table->integer('invoice_id');
|
||||
$table->integer('invoice_item_id');
|
||||
$table->integer('tax_id');
|
||||
$table->string('name');
|
||||
$table->double('amount', 15, 4)->default('0.0000');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index('company_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::drop('invoice_item_taxes');
|
||||
}
|
||||
}
|
28
public/css/app.css
vendored
28
public/css/app.css
vendored
@ -744,4 +744,32 @@ input[type="number"] {
|
||||
.col-md-6.input-group-invoice-text {
|
||||
padding-left: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
#items .select2-container--default .select2-selection--multiple .select2-selection__choice {
|
||||
background-color: #6da252;
|
||||
border: 1px solid #6da252;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
#items .select2-container--default .select2-selection--multiple .select2-selection__choice__remove {
|
||||
color: #fffdfd;
|
||||
}
|
||||
|
||||
#items span.select2.select2-container.select2-container--default .select2-selection.select2-selection--multiple {
|
||||
border-color: #d2d6de;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
#items .select2-container--default.select2-container--focus .select2-selection--multiple {
|
||||
border-color: #6da252;
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
#tax-add-new {
|
||||
padding: 6px 12px;
|
||||
}
|
||||
|
||||
#items .select2-search__field {
|
||||
padding-left: 15px;
|
||||
}
|
@ -39,14 +39,6 @@ return [
|
||||
'paid' => 'Paid',
|
||||
],
|
||||
|
||||
'taxes' => [
|
||||
'position' => 'Position',
|
||||
'positions' => [
|
||||
'before' => 'Before Subtotal (GST)',
|
||||
'after' => 'After Subtotal (PST)',
|
||||
],
|
||||
],
|
||||
|
||||
'messages' => [
|
||||
'received' => 'Bill marked as received successfully!',
|
||||
],
|
||||
|
@ -42,14 +42,6 @@ return [
|
||||
'paid' => 'Paid',
|
||||
],
|
||||
|
||||
'taxes' => [
|
||||
'position' => 'Position',
|
||||
'positions' => [
|
||||
'before' => 'Before Subtotal (GST)',
|
||||
'after' => 'After Subtotal (PST)',
|
||||
],
|
||||
],
|
||||
|
||||
'messages' => [
|
||||
'email_sent' => 'Invoice email has been sent successfully!',
|
||||
'marked_sent' => 'Invoice marked as sent successfully!',
|
||||
|
@ -96,7 +96,6 @@
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" id="button-tax" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button>
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right"><span id="tax-total">0</span></td>
|
||||
@ -131,7 +130,7 @@
|
||||
|
||||
{{ Form::recurring('create') }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'),[]) }}
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment')) }}
|
||||
|
||||
{{ Form::hidden('vendor_name', old('vendor_name'), ['id' => 'vendor_name']) }}
|
||||
{{ Form::hidden('vendor_email', old('vendor_email'), ['id' => 'vendor_email']) }}
|
||||
@ -170,7 +169,6 @@
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var item_row = '{{ $item_row }}';
|
||||
var tax_row = '0';
|
||||
|
||||
$(document).on('click', '#button-add-item', function (e) {
|
||||
var currency_code = $('#currency_code').val();
|
||||
@ -191,6 +189,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -250,6 +256,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -271,6 +285,24 @@
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
});
|
||||
|
||||
$(document).on('click', '#tax-add-new', function(e){
|
||||
tax_name = $('.select2-search__field').val();
|
||||
|
||||
$('#modal-create-tax').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/taxes/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {name: tax_name},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
|
||||
|
||||
$(document).on('click', '.form-control.typeahead', function() {
|
||||
@ -362,121 +394,12 @@
|
||||
$('a[rel=popover]').trigger('click');
|
||||
});
|
||||
|
||||
$('#button-tax').popover({
|
||||
html: true,
|
||||
placement: 'left',
|
||||
title: '{{ trans('bills.tax') }}',
|
||||
content: function () {
|
||||
html = '<div class="tax box-body">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('position', trans('bills.taxes.position'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::select('position', ['GST' => trans('bills.taxes.positions.before'), 'PST' => trans('bills.taxes.positions.after')], null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans('bills.taxes.position')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('tax_id', trans_choice('general.taxes', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax-id">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' <select class="form-control" id="tax_id" name="tax_id">';
|
||||
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
|
||||
@foreach($taxes as $tax_id => $tax_title)
|
||||
html += ' <option value="{{ $tax_id }}">{{ $tax_title }}</option>';
|
||||
@endforeach
|
||||
html += ' <option value="add-new">+ {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</option>';
|
||||
html += ' </select>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
html += '<div class="tax box-footer">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' <div class="form-group no-margin">';
|
||||
html += ' {!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' => 'save-tax','class' => 'btn btn-success']) !!}';
|
||||
html += ' <a href="javascript:void(0)" id="cancel-tax" class="btn btn-default"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</a>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#tax_id', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).val() == 'add-new') {
|
||||
html = ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('name', trans('general.name'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
|
||||
html += ' {!! Form::text('name', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('general.name')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('rate', trans('taxes.rate'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::text('rate', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('taxes.rate')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
|
||||
$('.tax.box-body').append(html);
|
||||
} else {
|
||||
$('.tax.box-body #name').parent().parent().remove();
|
||||
$('.tax.box-body #rate').parent().parent().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '#save-tax', function(){
|
||||
position = $('.tax.box-body #position').val();
|
||||
tax_id = $('.tax.box-body #tax_id').val();
|
||||
|
||||
html = '';
|
||||
|
||||
if (tax_id == 'add-new') {
|
||||
|
||||
} else {
|
||||
html = '<tr id="tr-multiple-tax-' + tax_row + '">';
|
||||
html += ' <td class="text-right" colspan="5">';
|
||||
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>';
|
||||
html += ' <strong>' + $(".tax.box-body #tax_id option:selected").text() + '</strong>';
|
||||
html += ' </td>';
|
||||
html += ' <td class="text-right">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][position]" value="' + position + '" type="hidden" id="input-position-multiple-tax-' + tax_row + '">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][tax_id]" value="' + tax_id + '" type="hidden" id="input-tax-id-multiple-tax-' + tax_row + '">';
|
||||
html += ' <span id="multiple-tax-' + tax_row + '-total">0</span>';
|
||||
html += ' </td>';
|
||||
html += '</tr>';
|
||||
}
|
||||
|
||||
if (position == 'GST') {
|
||||
$('#tr-subtotal').before(html);
|
||||
} else {
|
||||
$('#tr-discount').after(html);
|
||||
}
|
||||
|
||||
tax_row++;
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
|
||||
totalItem();
|
||||
});
|
||||
|
||||
$(document).on('click', '#cancel-tax', function(){
|
||||
$('#discount').val('');
|
||||
|
||||
totalItem();
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
});
|
||||
|
||||
$(document).on('change', '#currency_code, #items tbody select', function(){
|
||||
totalItem();
|
||||
});
|
||||
|
||||
var focus = false;
|
||||
|
||||
var focus = false;
|
||||
|
||||
$(document).on('focusin', '#items .input-price', function(){
|
||||
focus = true;
|
||||
});
|
||||
@ -549,7 +472,7 @@
|
||||
url: '{{ url("common/items/totalItem") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select').serialize(),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
success: function(data) {
|
||||
if (data) {
|
||||
@ -564,12 +487,6 @@
|
||||
$('#tax-total').html(data.tax_total);
|
||||
$('#grand-total').html(data.grand_total);
|
||||
|
||||
if (data.multible_taxes) {
|
||||
$.each( data.multible_taxes, function( key, value ) {
|
||||
$('#' + key).html(value);
|
||||
});
|
||||
}
|
||||
|
||||
$('.input-price').each(function(){
|
||||
input_price_id = $(this).attr('id');
|
||||
input_currency_id = input_price_id.replace('price', 'currency');
|
||||
|
@ -70,24 +70,6 @@
|
||||
<td class="text-right" colspan="5"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
@foreach($bill->totals as $bill_total)
|
||||
@if(strpos($bill_total, 'gst') === false)
|
||||
@php continue; @endphp
|
||||
@endif
|
||||
@php $tax_code = explode('-', $bill_total->code); @endphp
|
||||
<tr>
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" onclick="$(this).tooltip('destroy'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
|
||||
<strong>{{ $bill_total->name }}</strong>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<input name="multiple_tax[{{ $tax_row }}][position]" value="GST" type="hidden" id="input-position-multiple-tax-{{ $tax_row }}">
|
||||
<input name="multiple_tax[{{ $tax_row }}][tax_id]" value="{{ $tax_code[1] }}" type="hidden" id="input-tax-id-multiple-tax-{{ $tax_row }}">
|
||||
<span id="multiple-tax-{{ $tax_row }}-total">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
@php $tax_row++; @endphp
|
||||
@endforeach
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right" colspan="5"><strong>{{ trans('bills.sub_total') }}</strong></td>
|
||||
@ -105,28 +87,9 @@
|
||||
</td>
|
||||
</tr>
|
||||
@stack('add_discount_td_end')
|
||||
@foreach($bill->totals as $bill_total)
|
||||
@if(strpos($bill_total, 'pst') === false)
|
||||
@php continue; @endphp
|
||||
@endif
|
||||
@php $tax_code = explode('-', $bill_total->code); @endphp
|
||||
<tr>
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" onclick="$(this).tooltip('destroy'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
|
||||
<strong>{{ $bill_total->name }}</strong>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<input name="multiple_tax[{{ $tax_row }}][position]" value="PST" type="hidden" id="input-position-multiple-tax-{{ $tax_row }}">
|
||||
<input name="multiple_tax[{{ $tax_row }}][tax_id]" value="{{ $tax_code[1] }}" type="hidden" id="input-tax-id-multiple-tax-{{ $tax_row }}">
|
||||
<span id="multiple-tax-{{ $tax_row }}-total">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
@php $tax_row++; @endphp
|
||||
@endforeach
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" id="button-tax" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button>
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right"><span id="tax-total">0</span></td>
|
||||
@ -149,7 +112,7 @@
|
||||
|
||||
{{ Form::recurring('edit', $bill) }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'),[]) }}
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment')) }}
|
||||
|
||||
{{ Form::hidden('vendor_name', old('customer_name', null), ['id' => 'vendor_name']) }}
|
||||
{{ Form::hidden('vendor_email', old('vendor_email', null), ['id' => 'vendor_email']) }}
|
||||
@ -207,6 +170,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -229,6 +200,24 @@
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#tax-add-new', function(e){
|
||||
tax_name = $('.select2-search__field').val();
|
||||
|
||||
$('#modal-create-tax').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/taxes/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {name: tax_name},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$(".input-price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
@ -268,6 +257,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -405,121 +402,11 @@
|
||||
$('a[rel=popover]').trigger('click');
|
||||
});
|
||||
|
||||
$('#button-tax').popover({
|
||||
html: true,
|
||||
placement: 'left',
|
||||
title: '{{ trans('bills.tax') }}',
|
||||
content: function () {
|
||||
html = '<div class="tax box-body">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('position', trans('bills.taxes.position'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::select('position', ['GST' => trans('bills.taxes.positions.before'), 'PST' => trans('bills.taxes.positions.after')], null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans('bills.taxes.position')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('tax_id', trans_choice('general.taxes', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax-id">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' <select class="form-control" id="tax_id" name="tax_id">';
|
||||
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
|
||||
@foreach($taxes as $tax_id => $tax_title)
|
||||
html += ' <option value="{{ $tax_id }}">{{ $tax_title }}</option>';
|
||||
@endforeach
|
||||
html += ' <option value="add-new">+ {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</option>';
|
||||
html += ' </select>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
html += '<div class="tax box-footer">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' <div class="form-group no-margin">';
|
||||
html += ' {!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' => 'save-tax','class' => 'btn btn-success']) !!}';
|
||||
html += ' <a href="javascript:void(0)" id="cancel-tax" class="btn btn-default"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</a>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#tax_id', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).val() == 'add-new') {
|
||||
html = ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('name', trans('general.name'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
|
||||
html += ' {!! Form::text('name', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('general.name')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('rate', trans('taxes.rate'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::text('rate', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('taxes.rate')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
|
||||
$('.tax.box-body').append(html);
|
||||
} else {
|
||||
$('.tax.box-body #name').parent().parent().remove();
|
||||
$('.tax.box-body #rate').parent().parent().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '#save-tax', function(){
|
||||
position = $('.tax.box-body #position').val();
|
||||
tax_id = $('.tax.box-body #tax_id').val();
|
||||
|
||||
html = '';
|
||||
|
||||
if (tax_id == 'add-new') {
|
||||
|
||||
} else {
|
||||
html = '<tr id="tr-multiple-tax-' + tax_row + '">';
|
||||
html += ' <td class="text-right" colspan="5">';
|
||||
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>';
|
||||
html += ' <strong>' + $(".tax.box-body #tax_id option:selected").text() + '</strong>';
|
||||
html += ' </td>';
|
||||
html += ' <td class="text-right">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][position]" value="' + position + '" type="hidden" id="input-position-multiple-tax-' + tax_row + '">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][tax_id]" value="' + tax_id + '" type="hidden" id="input-tax-id-multiple-tax-' + tax_row + '">';
|
||||
html += ' <span id="multiple-tax-' + tax_row + '-total">0</span>';
|
||||
html += ' </td>';
|
||||
html += '</tr>';
|
||||
}
|
||||
|
||||
if (position == 'GST') {
|
||||
$('#tr-subtotal').before(html);
|
||||
} else {
|
||||
$('#tr-discount').after(html);
|
||||
}
|
||||
|
||||
tax_row++;
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
|
||||
totalItem();
|
||||
});
|
||||
|
||||
$(document).on('click', '#cancel-tax', function(){
|
||||
$('#discount').val('');
|
||||
|
||||
totalItem();
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
});
|
||||
|
||||
$(document).on('change', '#currency_code, #items tbody select', function(){
|
||||
totalItem();
|
||||
});
|
||||
|
||||
var focus = false;
|
||||
|
||||
$(document).on('focusin', '#items .input-price', function(){
|
||||
focus = true;
|
||||
});
|
||||
@ -592,7 +479,7 @@
|
||||
url: '{{ url("common/items/totalItem") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'], #items input[type=\'number\'], #items input[type=\'hidden\'], #items textarea, #items select'),
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'], #items input[type=\'number\'], #items input[type=\'hidden\'], #items textarea, #items select').serialize(),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
success: function(data) {
|
||||
if (data) {
|
||||
@ -607,12 +494,6 @@
|
||||
$('#tax-total').html(data.tax_total);
|
||||
$('#grand-total').html(data.grand_total);
|
||||
|
||||
if (data.multible_taxes) {
|
||||
$.each( data.multible_taxes, function( key, value ) {
|
||||
$('#' + key).html(value);
|
||||
});
|
||||
}
|
||||
|
||||
$('.input-price').each(function(){
|
||||
input_price_id = $(this).attr('id');
|
||||
input_currency_id = input_price_id.replace('price', 'currency');
|
||||
|
@ -7,7 +7,7 @@
|
||||
</td>
|
||||
@stack('actions_td_end')
|
||||
@stack('name_td_start')
|
||||
<td {!! $errors->has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}">
|
||||
<td {!! $errors->has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}>
|
||||
@stack('name_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->name }}" class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('bills.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}" autocomplete="off">
|
||||
<input value="{{ empty($item) ? '' : $item->item_id }}" name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
|
||||
@ -16,7 +16,7 @@
|
||||
</td>
|
||||
@stack('name_td_end')
|
||||
@stack('quantity_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}>
|
||||
@stack('quantity_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->quantity }}" class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
|
||||
{!! $errors->first('item.' . $item_row . '.quantity', '<p class="help-block">:message</p>') !!}
|
||||
@ -24,7 +24,7 @@
|
||||
</td>
|
||||
@stack('quantity_td_end')
|
||||
@stack('price_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}>
|
||||
@stack('price_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->price }}" class="form-control text-right input-price" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
|
||||
<input value="{{ $currency->code }}" name="item[{{ $item_row }}][currency]" type="hidden" id="item-currency-{{ $item_row }}">
|
||||
@ -33,9 +33,9 @@
|
||||
</td>
|
||||
@stack('price_td_end')
|
||||
@stack('taxes_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
|
||||
@stack('tax_id_input_start')
|
||||
{!! Form::select('item[' . $item_row . '][tax_id]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
|
||||
@stack('tax_id_input_end')
|
||||
</td>
|
||||
|
@ -96,7 +96,6 @@
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" id="button-tax" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button>
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right"><span id="tax-total">0</span></td>
|
||||
@ -170,7 +169,6 @@
|
||||
@push('scripts')
|
||||
<script type="text/javascript">
|
||||
var item_row = '{{ $item_row }}';
|
||||
var tax_row = '0';
|
||||
|
||||
$(document).on('click', '#button-add-item', function (e) {
|
||||
var currency_code = $('#currency_code').val();
|
||||
@ -191,6 +189,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -249,8 +255,15 @@
|
||||
$(".tax-select2").select2({
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
minimumResultsForSearch: '1',
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -272,6 +285,24 @@
|
||||
placeholder : '{{ trans('general.form.no_file_selected') }}'
|
||||
});
|
||||
|
||||
$(document).on('click', '#tax-add-new', function(e){
|
||||
tax_name = $('.select2-search__field').val();
|
||||
|
||||
$('#modal-create-tax').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/taxes/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {name: tax_name},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var autocomplete_path = "{{ url('common/items/autocomplete') }}";
|
||||
|
||||
$(document).on('click', '.form-control.typeahead', function() {
|
||||
@ -363,121 +394,12 @@
|
||||
$('a[rel=popover]').trigger('click');
|
||||
});
|
||||
|
||||
$('#button-tax').popover({
|
||||
html: true,
|
||||
placement: 'left',
|
||||
title: '{{ trans('invoices.tax') }}',
|
||||
content: function () {
|
||||
html = '<div class="tax box-body">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('position', trans('invoices.taxes.position'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::select('position', ['GST' => trans('invoices.taxes.positions.before'), 'PST' => trans('invoices.taxes.positions.after')], null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans('invoices.taxes.position')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('tax_id', trans_choice('general.taxes', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax-id">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' <select class="form-control" id="tax_id" name="tax_id">';
|
||||
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
|
||||
@foreach($taxes as $tax_id => $tax_title)
|
||||
html += ' <option value="{{ $tax_id }}">{{ $tax_title }}</option>';
|
||||
@endforeach
|
||||
html += ' <option value="add-new">+ {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</option>';
|
||||
html += ' </select>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
html += '<div class="tax box-footer">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' <div class="form-group no-margin">';
|
||||
html += ' {!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' => 'save-tax','class' => 'btn btn-success']) !!}';
|
||||
html += ' <a href="javascript:void(0)" id="cancel-tax" class="btn btn-default"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</a>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#tax_id', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).val() == 'add-new') {
|
||||
html = ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('name', trans('general.name'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
|
||||
html += ' {!! Form::text('name', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('general.name')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('rate', trans('taxes.rate'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::text('rate', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('taxes.rate')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
|
||||
$('.tax.box-body').append(html);
|
||||
} else {
|
||||
$('.tax.box-body #name').parent().parent().remove();
|
||||
$('.tax.box-body #rate').parent().parent().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '#save-tax', function(){
|
||||
position = $('.tax.box-body #position').val();
|
||||
tax_id = $('.tax.box-body #tax_id').val();
|
||||
|
||||
html = '';
|
||||
|
||||
if (tax_id == 'add-new') {
|
||||
|
||||
} else {
|
||||
html = '<tr id="tr-multiple-tax-' + tax_row + '">';
|
||||
html += ' <td class="text-right" colspan="5">';
|
||||
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>';
|
||||
html += ' <strong>' + $(".tax.box-body #tax_id option:selected").text() + '</strong>';
|
||||
html += ' </td>';
|
||||
html += ' <td class="text-right">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][position]" value="' + position + '" type="hidden" id="input-position-multiple-tax-' + tax_row + '">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][tax_id]" value="' + tax_id + '" type="hidden" id="input-tax-id-multiple-tax-' + tax_row + '">';
|
||||
html += ' <span id="multiple-tax-' + tax_row + '-total">0</span>';
|
||||
html += ' </td>';
|
||||
html += '</tr>';
|
||||
}
|
||||
|
||||
if (position == 'GST') {
|
||||
$('#tr-subtotal').before(html);
|
||||
} else {
|
||||
$('#tr-discount').after(html);
|
||||
}
|
||||
|
||||
tax_row++;
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
|
||||
totalItem();
|
||||
});
|
||||
|
||||
$(document).on('click', '#cancel-tax', function(){
|
||||
$('#discount').val('');
|
||||
|
||||
totalItem();
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
});
|
||||
|
||||
$(document).on('change', '#currency_code, #items tbody select', function(){
|
||||
totalItem();
|
||||
});
|
||||
|
||||
var focus = false;
|
||||
|
||||
var focus = false;
|
||||
|
||||
$(document).on('focusin', '#items .input-price', function(){
|
||||
focus = true;
|
||||
});
|
||||
@ -550,7 +472,7 @@
|
||||
url: '{{ url("common/items/totalItem") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select'),
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'],#items input[type=\'number\'],#items input[type=\'hidden\'], #items textarea, #items select').serialize(),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
success: function(data) {
|
||||
if (data) {
|
||||
@ -565,12 +487,6 @@
|
||||
$('#tax-total').html(data.tax_total);
|
||||
$('#grand-total').html(data.grand_total);
|
||||
|
||||
if (data.multible_taxes) {
|
||||
$.each( data.multible_taxes, function( key, value ) {
|
||||
$('#' + key).html(value);
|
||||
});
|
||||
}
|
||||
|
||||
$('.input-price').each(function(){
|
||||
input_price_id = $(this).attr('id');
|
||||
input_currency_id = input_price_id.replace('price', 'currency');
|
||||
|
@ -70,24 +70,6 @@
|
||||
<td class="text-right" colspan="5"></td>
|
||||
</tr>
|
||||
@stack('add_item_td_end')
|
||||
@foreach($invoice->totals as $invoice_total)
|
||||
@if(strpos($invoice_total, 'gst') === false)
|
||||
@php continue; @endphp
|
||||
@endif
|
||||
@php $tax_code = explode('-', $invoice_total->code); @endphp
|
||||
<tr>
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" onclick="$(this).tooltip('destroy'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
|
||||
<strong>{{ $invoice_total->name }}</strong>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<input name="multiple_tax[{{ $tax_row }}][position]" value="GST" type="hidden" id="input-position-multiple-tax-{{ $tax_row }}">
|
||||
<input name="multiple_tax[{{ $tax_row }}][tax_id]" value="{{ $tax_code[1] }}" type="hidden" id="input-tax-id-multiple-tax-{{ $tax_row }}">
|
||||
<span id="multiple-tax-{{ $tax_row }}-total">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
@php $tax_row++; @endphp
|
||||
@endforeach
|
||||
@stack('sub_total_td_start')
|
||||
<tr id="tr-subtotal">
|
||||
<td class="text-right" colspan="5"><strong>{{ trans('invoices.sub_total') }}</strong></td>
|
||||
@ -105,28 +87,9 @@
|
||||
</td>
|
||||
</tr>
|
||||
@stack('add_discount_td_end')
|
||||
@foreach($invoice->totals as $invoice_total)
|
||||
@if(strpos($invoice_total, 'pst') === false)
|
||||
@php continue; @endphp
|
||||
@endif
|
||||
@php $tax_code = explode('-', $invoice_total->code); @endphp
|
||||
<tr>
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" onclick="$(this).tooltip('destroy'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>
|
||||
<strong>{{ $invoice_total->name }}</strong>
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<input name="multiple_tax[{{ $tax_row }}][position]" value="PST" type="hidden" id="input-position-multiple-tax-{{ $tax_row }}">
|
||||
<input name="multiple_tax[{{ $tax_row }}][tax_id]" value="{{ $tax_code[1] }}" type="hidden" id="input-tax-id-multiple-tax-{{ $tax_row }}">
|
||||
<span id="multiple-tax-{{ $tax_row }}-total">0</span>
|
||||
</td>
|
||||
</tr>
|
||||
@php $tax_row++; @endphp
|
||||
@endforeach
|
||||
@stack('tax_total_td_start')
|
||||
<tr id="tr-tax">
|
||||
<td class="text-right" colspan="5">
|
||||
<button type="button" id="button-tax" data-toggle="tooltip" title="{{ trans('general.add') }}" class="btn btn-xs btn-primary" data-original-title="{{ trans('general.add') }}"><i class="fa fa-plus"></i></button>
|
||||
<strong>{{ trans_choice('general.taxes', 1) }}</strong>
|
||||
</td>
|
||||
<td class="text-right"><span id="tax-total">0</span></td>
|
||||
@ -207,6 +170,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -229,6 +200,24 @@
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#tax-add-new', function(e){
|
||||
tax_name = $('.select2-search__field').val();
|
||||
|
||||
$('#modal-create-tax').remove();
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/taxes/create") }}',
|
||||
type: 'GET',
|
||||
dataType: 'JSON',
|
||||
data: {name: tax_name},
|
||||
success: function(json) {
|
||||
if (json['success']) {
|
||||
$('body').append(json['html']);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$(".input-price").maskMoney({
|
||||
thousands : '{{ $currency->thousands_separator }}',
|
||||
@ -268,6 +257,14 @@
|
||||
placeholder: {
|
||||
id: '-1', // the value of the option
|
||||
text: "{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}"
|
||||
},
|
||||
escapeMarkup: function (markup) {
|
||||
return markup;
|
||||
},
|
||||
language: {
|
||||
noResults: function () {
|
||||
return '<span id="tax-add-new"><i class="fa fa-plus"> {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</span>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -405,121 +402,12 @@
|
||||
$('a[rel=popover]').trigger('click');
|
||||
});
|
||||
|
||||
$('#button-tax').popover({
|
||||
html: true,
|
||||
placement: 'left',
|
||||
title: '{{ trans('invoices.tax') }}',
|
||||
content: function () {
|
||||
html = '<div class="tax box-body">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('position', trans('invoices.taxes.position'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::select('position', ['GST' => trans('invoices.taxes.positions.before'), 'PST' => trans('invoices.taxes.positions.after')], null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.select.field', ['field' => trans('invoices.taxes.position')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('tax_id', trans_choice('general.taxes', 1), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group" id="input-tax-id">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' <select class="form-control" id="tax_id" name="tax_id">';
|
||||
html += ' <option selected="selected" value="">{{ trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)]) }}</option>';
|
||||
@foreach($taxes as $tax_id => $tax_title)
|
||||
html += ' <option value="{{ $tax_id }}">{{ $tax_title }}</option>';
|
||||
@endforeach
|
||||
html += ' <option value="add-new">+ {{ trans('general.title.new', ['type' => trans_choice('general.tax_rates', 1)]) }}</option>';
|
||||
html += ' </select>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
html += '<div class="tax box-footer">';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' <div class="form-group no-margin">';
|
||||
html += ' {!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' => 'save-tax','class' => 'btn btn-success']) !!}';
|
||||
html += ' <a href="javascript:void(0)" id="cancel-tax" class="btn btn-default"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</a>';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += '</div>';
|
||||
|
||||
return html;
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('change', '#tax_id', function(e){
|
||||
e.preventDefault();
|
||||
|
||||
if ($(this).val() == 'add-new') {
|
||||
html = ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('name', trans('general.name'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-id-card-o"></i></div>';
|
||||
html += ' {!! Form::text('name', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('general.name')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
html += ' <div class="col-md-12">';
|
||||
html += ' {!! Form::label('rate', trans('taxes.rate'), ['class' => 'control-label']) !!}';
|
||||
html += ' <div class="input-group">';
|
||||
html += ' <div class="input-group-addon"><i class="fa fa-percent"></i></div>';
|
||||
html += ' {!! Form::text('rate', null, array_merge(['class' => 'form-control', 'placeholder' => trans('general.form.enter', ['field' => trans('taxes.rate')])])) !!}';
|
||||
html += ' </div>';
|
||||
html += ' </div>';
|
||||
|
||||
$('.tax.box-body').append(html);
|
||||
} else {
|
||||
$('.tax.box-body #name').parent().parent().remove();
|
||||
$('.tax.box-body #rate').parent().parent().remove();
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('click', '#save-tax', function(){
|
||||
position = $('.tax.box-body #position').val();
|
||||
tax_id = $('.tax.box-body #tax_id').val();
|
||||
|
||||
html = '';
|
||||
|
||||
if (tax_id == 'add-new') {
|
||||
|
||||
} else {
|
||||
html = '<tr id="tr-multiple-tax-' + tax_row + '">';
|
||||
html += ' <td class="text-right" colspan="5">';
|
||||
html += ' <button type="button" onclick="$(this).tooltip(\'destroy\'); $(this).parent().parent().remove(); totalItem();" data-toggle="tooltip" title="{{ trans('general.delete') }}" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>';
|
||||
html += ' <strong>' + $(".tax.box-body #tax_id option:selected").text() + '</strong>';
|
||||
html += ' </td>';
|
||||
html += ' <td class="text-right">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][position]" value="' + position + '" type="hidden" id="input-position-multiple-tax-' + tax_row + '">';
|
||||
html += ' <input name="multiple_tax[' + tax_row + '][tax_id]" value="' + tax_id + '" type="hidden" id="input-tax-id-multiple-tax-' + tax_row + '">';
|
||||
html += ' <span id="multiple-tax-' + tax_row + '-total">0</span>';
|
||||
html += ' </td>';
|
||||
html += '</tr>';
|
||||
}
|
||||
|
||||
if (position == 'GST') {
|
||||
$('#tr-subtotal').before(html);
|
||||
} else {
|
||||
$('#tr-discount').after(html);
|
||||
}
|
||||
|
||||
tax_row++;
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
|
||||
totalItem();
|
||||
});
|
||||
|
||||
$(document).on('click', '#cancel-tax', function(){
|
||||
$('#discount').val('');
|
||||
|
||||
totalItem();
|
||||
|
||||
$('#button-tax').trigger('click');
|
||||
});
|
||||
|
||||
$(document).on('change', '#currency_code, #items tbody select', function(){
|
||||
totalItem();
|
||||
});
|
||||
|
||||
var focus = false;
|
||||
|
||||
|
||||
$(document).on('focusin', '#items .input-price', function(){
|
||||
focus = true;
|
||||
});
|
||||
@ -592,7 +480,7 @@
|
||||
url: '{{ url("common/items/totalItem") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'], #items input[type=\'number\'], #items input[type=\'hidden\'], #items textarea, #items select'),
|
||||
data: $('#currency_code, #discount input[type=\'number\'], #items input[type=\'text\'], #items input[type=\'number\'], #items input[type=\'hidden\'], #items textarea, #items select').serialize(),
|
||||
headers: { 'X-CSRF-TOKEN': '{{ csrf_token() }}' },
|
||||
success: function(data) {
|
||||
if (data) {
|
||||
@ -607,12 +495,6 @@
|
||||
$('#tax-total').html(data.tax_total);
|
||||
$('#grand-total').html(data.grand_total);
|
||||
|
||||
if (data.multible_taxes) {
|
||||
$.each( data.multible_taxes, function( key, value ) {
|
||||
$('#' + key).html(value);
|
||||
});
|
||||
}
|
||||
|
||||
$('.input-price').each(function(){
|
||||
input_price_id = $(this).attr('id');
|
||||
input_currency_id = input_price_id.replace('price', 'currency');
|
||||
|
@ -7,7 +7,7 @@
|
||||
</td>
|
||||
@stack('actions_td_end')
|
||||
@stack('name_td_start')
|
||||
<td {!! $errors->has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}">
|
||||
<td {!! $errors->has('item.' . $item_row . '.name') ? 'class="has-error"' : '' !!}>
|
||||
@stack('name_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->name }}" class="form-control typeahead" required="required" placeholder="{{ trans('general.form.enter', ['field' => trans_choice('invoices.item_name', 1)]) }}" name="item[{{ $item_row }}][name]" type="text" id="item-name-{{ $item_row }}" autocomplete="off">
|
||||
<input value="{{ empty($item) ? '' : $item->item_id }}" name="item[{{ $item_row }}][item_id]" type="hidden" id="item-id-{{ $item_row }}">
|
||||
@ -16,7 +16,7 @@
|
||||
</td>
|
||||
@stack('name_td_end')
|
||||
@stack('quantity_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . '.quantity') ? 'class="has-error"' : '' }}>
|
||||
@stack('quantity_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->quantity }}" class="form-control text-center" required="required" name="item[{{ $item_row }}][quantity]" type="text" id="item-quantity-{{ $item_row }}">
|
||||
{!! $errors->first('item.' . $item_row . '.quantity', '<p class="help-block">:message</p>') !!}
|
||||
@ -24,7 +24,7 @@
|
||||
</td>
|
||||
@stack('quantity_td_end')
|
||||
@stack('price_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . 'price') ? 'class="has-error"' : '' }}>
|
||||
@stack('price_input_start')
|
||||
<input value="{{ empty($item) ? '' : $item->price }}" class="form-control text-right input-price" required="required" name="item[{{ $item_row }}][price]" type="text" id="item-price-{{ $item_row }}">
|
||||
<input value="{{ $currency->code }}" name="item[{{ $item_row }}][currency]" type="hidden" id="item-currency-{{ $item_row }}">
|
||||
@ -33,9 +33,9 @@
|
||||
</td>
|
||||
@stack('price_td_end')
|
||||
@stack('taxes_td_start')
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}">
|
||||
<td {{ $errors->has('item.' . $item_row . '.tax_id') ? 'class="has-error"' : '' }}>
|
||||
@stack('tax_id_input_start')
|
||||
{!! Form::select('item[' . $item_row . '][tax_id]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'placeholder' => trans('general.form.select.field', ['field' => trans_choice('general.taxes', 1)])]) !!}
|
||||
{!! Form::select('item[' . $item_row . '][tax_id][]', $taxes, empty($item) ? setting('general.default_tax') : $item->tax_id, ['id'=> 'item-tax-'. $item_row, 'class' => 'form-control tax-select2', 'multiple' => 'true']) !!}
|
||||
{!! $errors->first('item.' . $item_row . '.tax_id', '<p class="help-block">:message</p>') !!}
|
||||
@stack('tax_id_input_end')
|
||||
</td>
|
||||
|
71
resources/views/modals/taxes/create.blade.php
Normal file
71
resources/views/modals/taxes/create.blade.php
Normal file
@ -0,0 +1,71 @@
|
||||
<div class="modal fade" id="modal-create-tax" style="display: none;">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title">{{ trans('general.title.new', ['type' => trans_choice('general.taxes', 1)]) }}</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
{!! Form::open(['id' => 'form-create-tax', 'role' => 'form', 'class' => 'form-loading-button']) !!}
|
||||
<div class="row">
|
||||
{{ Form::textGroup('name', trans('general.name'), 'id-card-o') }}
|
||||
|
||||
{{ Form::textGroup('rate', trans('taxes.rate'), 'percent') }}
|
||||
|
||||
{!! Form::hidden('enabled', '1', []) !!}
|
||||
</div>
|
||||
{!! Form::close() !!}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<div class="pull-left">
|
||||
{!! Form::button('<span class="fa fa-save"></span> ' . trans('general.save'), ['type' => 'button', 'id' =>'button-create-tax', 'class' => 'btn btn-success button-submit', 'data-loading-text' => trans('general.loading')]) !!}
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><span class="fa fa-times-circle"></span> {{ trans('general.cancel') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
$('#modal-create-tax').modal('show');
|
||||
});
|
||||
|
||||
$(document).on('click', '#button-create-tax', function (e) {
|
||||
$('#modal-create-tax .modal-header').before('<span id="span-loading" style="position: absolute; height: 100%; width: 100%; z-index: 99; background: #6da252; opacity: 0.4;"><i class="fa fa-spinner fa-spin" style="font-size: 16em !important;margin-left: 35%;margin-top: 8%;"></i></span>');
|
||||
|
||||
$.ajax({
|
||||
url: '{{ url("modals/taxes") }}',
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
data: $("#form-create-tax").serialize(),
|
||||
beforeSend: function () {
|
||||
$(".form-group").removeClass("has-error");
|
||||
$(".help-block").remove();
|
||||
},
|
||||
success: function(json) {
|
||||
var data = json['data'];
|
||||
|
||||
$('#span-loading').remove();
|
||||
|
||||
$('#modal-create-tax').modal('hide');
|
||||
|
||||
$("#tax_id").append('<option value="' + data.id + '" selected="selected">' + data.name + '</option>');
|
||||
$('#tax_id').trigger('change');
|
||||
$("#tax_id").select2('refresh');
|
||||
},
|
||||
error: function(error, textStatus, errorThrown) {
|
||||
$('#span-loading').remove();
|
||||
|
||||
if (error.responseJSON.name) {
|
||||
$("#modal-create-tax input[name='name']").parent().parent().addClass('has-error');
|
||||
$("#modal-create-tax input[name='name']").parent().after('<p class="help-block">' + error.responseJSON.name + '</p>');
|
||||
}
|
||||
|
||||
if (error.responseJSON.rate) {
|
||||
$("#modal-create-tax input[name='rate']").parent().parent().addClass('has-error');
|
||||
$("#modal-create-tax input[name='rate']").parent().after('<p class="help-block">' + error.responseJSON.rate + '</p>');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
@ -202,6 +202,15 @@ Route::group(['middleware' => 'language'], function () {
|
||||
]]);
|
||||
Route::resource('invoices/{invoice}/payment', 'Modals\InvoicePayments', ['middleware' => ['dateformat', 'money']]);
|
||||
Route::resource('bills/{bill}/payment', 'Modals\BillPayments', ['middleware' => ['dateformat', 'money']]);
|
||||
Route::resource('taxes', 'Modals\Taxes', ['names' => [
|
||||
'index' => 'modals.taxes.index',
|
||||
'create' => 'modals.taxes.create',
|
||||
'store' => 'modals.taxes.store',
|
||||
'show' => 'modals.taxes.show',
|
||||
'edit' => 'modals.taxes.edit',
|
||||
'update' => 'modals.taxes.update',
|
||||
'destroy' => 'modals.taxes.destroy',
|
||||
]]);
|
||||
});
|
||||
|
||||
/* @deprecated */
|
||||
|
Loading…
x
Reference in New Issue
Block a user