function addBlankTax($quotation_id) { $default_tax = LbTax::model()->getDefaultTax(); $this->lb_quotation_id = $quotation_id; $this->lb_quotation_tax_id = $default_tax !== null ? $default_tax->lb_record_primary_key : '0'; $this->lb_quotation_tax_value = $default_tax !== null ? $default_tax->lb_tax_value : '0'; $this->lb_quotation_tax_total = 0; return $this->save(); }
public function actionIndex() { $taxModel = LbTax::model()->getTaxes(); $list = UserList::model()->getList(); $translate = Translate::model()->search(); $translate = new Translate('search'); $translate->unsetAttributes(); // clear any default values if (isset($_GET['Translate'])) { $translate->attributes = $_GET['Translate']; } LBApplication::render($this, 'index', array('taxModel' => $taxModel, 'list' => $list, 'translate' => $translate)); // $this->render('index'); }
public function actionAjaxGetTax() { // only proceed if tax id and line item primary key available $type = false; if (isset($_GET['type'])) { $type = $_GET['type']; } if (isset($_POST['tax_id'])) { if ($_POST['tax_id'] != 0) { // get tax record, so that we can determine the value $taxRecord = LbTax::model()->findByPk($_POST['tax_id']); } else { $taxRecord['lb_tax_value'] = 0; } if ($taxRecord) { LbVendorTax::model()->ajaxUpdateTaxes($taxRecord->lb_tax_name, $taxRecord->lb_tax_value, $_POST['line_item_pk'], $_POST['tax_id'], $_GET['id'], $type); LBApplication::renderPlain($this, array('content' => CJSON::encode($taxRecord))); } } }
/** * Add a new tax item * Usually use when user adds a new discount in discount table on the GUI * After that user will enter the value. But we need a blank line (like a form) for them first. * * @param $invoice_id * @return bool */ public function addBlankTax($invoice_id) { $default_tax = LbTax::model()->getDefaultTax(); $this->lb_invoice_id = $invoice_id; //$this->lb_invoice_item_description = ($default_tax !== null ? $default_tax->lb_tax_name : 'Tax'); $this->lb_invoice_item_description = $default_tax !== null ? $default_tax->lb_record_primary_key : 'null'; $this->lb_invoice_item_quantity = 1; $this->lb_invoice_item_value = $default_tax !== null ? $default_tax->lb_tax_value : '0'; $this->lb_invoice_item_total = 0; $this->lb_invoice_item_type = self::LB_INVOICE_ITEM_TYPE_TAX; return $this->save(); }
// Subtotal Invoice $invoice_subtotal_arr = LbInvoiceTotal::model()->getInvoiceTotal($model->lb_record_primary_key); // Discount Invoice $invoice_discount_arr = LbInvoiceItem::model()->getInvoiceDiscounts($model->lb_record_primary_key, 'ModelArray'); $invoice_discount = ""; foreach ($invoice_discount_arr as $invoice_discount_row) { $invoice_discount .= '<tr><td>' . $invoice_discount_row['lb_invoice_item_description'] . ":" . '</td> <td>' . $currency_name . $strnum->adddotstring($invoice_discount_row['lb_invoice_item_total'], $thousand, $decimal) . '</td> </tr>'; } //End Discount // Tax Invoice $invoice_tax_arr = LbInvoiceItem::model()->getInvoiceTaxes($model->lb_record_primary_key, 'ModelArray'); $invoice_tax = ""; foreach ($invoice_tax_arr as $invoice_tax_row) { $tax_arr = LbTax::model()->find('lb_record_primary_key=' . $invoice_tax_row['lb_invoice_item_description']); if ($tax_arr['lb_tax_value'] != null && $tax_arr['lb_tax_name'] != null) { $tax_name = 'Tax'; if ($tax_arr['lb_tax_name'] != "") { $tax_name = $tax_arr['lb_tax_name']; } $invoice_tax .= '<tr> <td>' . $tax_name . ' (' . $tax_arr['lb_tax_value'] . "%):" . '</td> <td>' . $currency_name . $strnum->adddotstring($invoice_tax_row['lb_invoice_item_total'], $thousand, $decimal) . '</td> </tr>'; } } // LOGO $company = isset($model->owner) ? $model->lb_invoice_company_id : ''; $folder = 'images/logo/'; $path = "./images/logo/";
// } // echo $form->dropDownListRow($model, 'lb_expenses_recurring_id', $recurring); // $bank_accounts = LbBankAccount::model()->getBankAccount(Yii::app()->user->id); $bank_account_arr = array(); if (count($bankaccounts) > 0) { foreach ($bankaccounts as $data_bank) { $bank_account_arr[$data_bank->lb_record_primary_key] = $data_bank->lb_bank_account; } } $option_bank_acc = array('' => 'Choose Bank Account'); if (UserList::model()->getItemsForListCode('BankAcount')) { $option_bank_acc += UserList::model()->getItemsForListCode('BankAcount'); } echo $form->dropDownListRow($model, 'lb_expenses_bank_account_id', CHtml::listData($option_bank_acc, 'system_list_item_id', 'system_list_item_name')); $arr_tax = LbTax::model()->getTaxes("", LbTax::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); // echo '<pre>'; // print_r($arr_tax); $option_tax = '<option value="0">---</option>'; foreach ($arr_tax as $data) { $option_tax .= '<option value="' . $data['lb_record_primary_key'] . '">' . $data['lb_tax_value'] . '</option>'; } echo '<div class="control-group" id="tax_0">'; echo CHtml::label('Taxes', 'LbExpenses_lb_tax_id', array('class' => 'control-label')); echo '<div class="controls">'; // echo '<a href="#" onClick="delete_tax(0); return false;" rel="tooltip" class="delete" data-original-title="Delete"><i class="icon-trash"></i></a>'; echo '<select name="LbExpensesTax[lb_tax_id][]" id="LbExpenses_lb_tax_id_0" onchange="changeTax(0);">' . $option_tax . '</select>'; echo ' '; // echo CHtml::dropDownList('LbExpenses_lb_tax_id', '', $option_tax, array('style'=>'width:50px;'));echo ' '; echo CHtml::textField('LbExpenses_lb_expenses_tax_total', '', array('class' => 'span2', 'id' => 'LbExpenses_lb_expenses_tax_total_0')); echo ' ';
public function actionAjaxUpdateFieldTax() { if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) { $id = $_POST['pk']; $attribute = $_POST['name']; $value = $_POST['value']; // get model $model = LbTax::model()->findByPk($id); // update $model->{$attribute} = $value; $model->save(); return true; } return false; }
/** * Thêm tax mặt định khi tạo một vendor mới * @param type $record_id = {vendor_id|vendor_invoice_id} * @param type $type = {vendor|supplier invoice} */ public function addLineTaxVendor($record_id, $type) { $default_tax = LbTax::model()->getDefaultTax(); $model = new LbVendorTax(); if ($type == LbVendorTax::LB_VENDOR_ITEM_TYPE_TAX) { $model->lb_vendor_id = $record_id; $model->lb_vendor_invoice_id = 0; } if ($type == LbVendorTax::LB_VENDOR_INVOICE_ITEM_TYPE_TAX) { $model->lb_vendor_invoice_id = $record_id; $model->lb_vendor_id = 0; } $model->lb_vendor_type = $type; $model->lb_vendor_tax_id = $default_tax !== null ? $default_tax->lb_record_primary_key : '0'; $model->lb_tax_name = $default_tax !== null ? $default_tax->lb_tax_name : '0'; $model->lb_vendor_tax_value = $default_tax !== null ? $default_tax->lb_tax_value : '0'; $model->lb_vendor_tax_total = 0; return $model->insert(); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new LbExpenses(); $model->attributes; $idPV = false; if (isset($_REQUEST['idPV'])) { $idPV = $_REQUEST['idPV']; } // $documentModel = new LbDocument(); $customerModel = new LbExpensesCustomer(); $invoiceModel = new LbExpensesInvoice(); $bankaccountModel = new LbBankAccount(); $bankaccounts = $bankaccountModel->getBankAccount(Yii::app()->user->id); if (isset($_POST['LbExpenses']) && floatval($_POST['LbExpenses']['lb_expenses_amount']) != 0) { $LbExpenses = $_POST['LbExpenses']; $model->attributes = $LbExpenses; $model->lb_expenses_date = date('Y-m-d', strtotime($_POST['LbExpenses']['lb_expenses_date'])); if ($model->save()) { LbExpenses::model()->setExpensesNextNum(LbExpenses::model()->getExpensesNextNum()); //********** Upload document *************// $documents = CUploadedFile::getInstancesByName('documents'); // proceed if the images have been set $i = 0; if (isset($documents) && count($documents) > 0) { // go through each uploaded image foreach ($documents as $document => $doc) { $i++; // tach filename va duoi $temp = explode('.', $doc->name); $duoi = '.' . $temp[count($temp) - 1]; $lendduoi = strlen($temp[count($temp) - 1]) + 1; $filename = substr($doc->name, 0, strlen($doc->name) - $lendduoi); $encoded_filename = str_replace(' ', '_', $filename) . '_expenses' . $model->lb_record_primary_key . '_' . $i . $duoi; if ($doc->saveAs(Yii::getPathOfAlias('webroot') . '/uploads/' . $encoded_filename)) { // add it to the main model now $documentModel = new LbDocument(); $documentModel->lb_document_parent_type = LbDocument::LB_DOCUMENT_PARENT_TYPE_EXPENSES; $documentModel->lb_document_parent_id = $model->lb_record_primary_key; $documentModel->lb_document_url = "/uploads/" . $encoded_filename; //it might be $img_add->name for you, filename is just what I chose to call it in my model $documentModel->lb_document_name = $doc->name; // this links your picture model to the main model (like your user, or profile model) $documentModel->lb_document_encoded_name = $encoded_filename; $documentModel->save(); // DONE } } } // *** End upload document *** // // ********* Add cusotmer **********// if (isset($_POST["LbExpensesCustomer"])) { $LbExpensesCustomer = $_POST['LbExpensesCustomer']; if (isset($LbExpensesCustomer['lb_customer_id']) && is_array($LbExpensesCustomer['lb_customer_id']) && count($LbExpensesCustomer['lb_customer_id']) > 0) { foreach ($LbExpensesCustomer['lb_customer_id'] as $customer) { if ($customer > 0) { $expensesCustomer = new LbExpensesCustomer(); $expensesCustomer->lb_expenses_id = $model->lb_record_primary_key; $expensesCustomer->lb_customer_id = $customer; $expensesCustomer->save(); } } } } // *** End add customer *** // // ********* Choose invoice **********// if (isset($_POST["LbExpensesInvoice"])) { $LbExpensesInvoice = $_POST['LbExpensesInvoice']; if (isset($LbExpensesInvoice['lb_invoice_id']) && is_array($LbExpensesInvoice['lb_invoice_id']) && count($LbExpensesInvoice['lb_invoice_id']) > 0) { foreach ($LbExpensesInvoice['lb_invoice_id'] as $invoice) { if ($invoice > 0) { $expensesInvoice = new LbExpensesInvoice(); $expensesInvoice->lb_expenses_id = $model->lb_record_primary_key; $expensesInvoice->lb_invoice_id = $invoice; $expensesInvoice->save(); } } } } //Insert Tax if (isset($_POST["LbExpensesTax"])) { $LbExpensesTax = $_POST['LbExpensesTax']; if (isset($LbExpensesTax['lb_tax_id']) && is_array($LbExpensesTax['lb_tax_id']) && count($LbExpensesTax['lb_tax_id']) > 0) { foreach ($LbExpensesTax['lb_tax_id'] as $tax) { if ($tax > 0) { $expensesTax = new LbExpensesTax(); $expensesTax->lb_expenses_id = $model->lb_record_primary_key; $expensesTax->lb_tax_id = $tax; $amount = $_POST['LbExpenses']['lb_expenses_amount']; $information_tax = LbTax::model()->findByPk($tax); $tax_value = $information_tax['lb_tax_value']; $expensesTax->lb_expenses_tax_total = $amount * $tax_value / 100; $expensesTax->save(); } } } } // *** End add invoice *** // //add ex in payment voucher if ($idPV) { $PvExpenses = new LbPvExpenses(); $PvExpenses->lb_expenses_id = $model->lb_record_primary_key; $PvExpenses->lb_payment_voucher_id = $idPV; $PvExpenses->insert(); } // echo '<pre>'; // print_r($_POST["LbExpensesTax"]); $this->redirect(array('view', 'id' => $model->lb_record_primary_key)); return; } } $this->render('create', array('model' => $model, 'customerModel' => $customerModel, 'invoiceModel' => $invoiceModel, 'bankaccounts' => $bankaccounts)); }
public function actionAjaxQuickCreateTax($id) { $model = new LbTax(); $submission_type = isset($_GET['form_type']) ? $_GET['form_type'] : 'default'; $quotationModel = LbQuotation::model()->findByPk($id); if (isset($_POST['LbTax'])) { $model->attributes = $_POST['LbTax']; $lbtax_arr = $_POST['LbTax']; if (!LbTax::model()->IsNameTax($lbtax_arr['lb_tax_name'])) { $error['error'] = "Tax Name Exist."; LBApplication::renderPlain($this, array('content' => CJSON::encode($error))); return false; } if ($model->save()) { $result['yes'] = true; if ($submission_type == 'ajax') { // auto add this tax item into this invoice $quotaitonTax = new LbQuotationTax(); if ($quotaitonTax->addTaxToQuotation($id, $model)) { $this->actionAjaxUpdateTaxs($id); } // print json result of this quotation item //LBApplication::renderPlain($this, array('content'=>CJSON::encode($result))); return true; } } } $submission_details = array(); $submission_details["type"] = $submission_type; LBApplication::render($this, '_form_tax', array('model' => $model, 'quotationModel' => $quotationModel, 'submission_details' => $submission_details)); }
<?php /* * @var $model LbInvoice */ $expenses_id = $model->lb_record_primary_key; $ex_tax = LbExpensesTax::model()->findAll('lb_expenses_id=' . $expenses_id); $i = 0; foreach ($ex_tax as $ex_invoice) { $tax = LbTax::model()->findByPk($ex_invoice['lb_tax_id']); $i++; echo "\n <div style='overflow:hidden; border-top: 1px solid #EEEEEE;margin-top: 5px;'>\n <div style='float:left;width:44%;'>\n <h4><span style='padding: 0 8px;background:#EEEEEE;border-radius:50%;'>{$i}</span> " . $tax['lb_tax_name'] . ' ' . $tax['lb_tax_value'] . "\n <span style='float:right'>\$" . number_format($ex_invoice['lb_expenses_tax_total'], 2, '.', ',') . "</span></h4>\n </div>"; echo "<div style='float:right;margin-top:5px;'>\n <a href='#' onclick='ajaxDeleteInvoiceExpenses(" . $ex_invoice['lb_record_primary_key'] . "); return false;'>\n <i class='icon-trash'></i>\n Delete\n </a>\n </div>"; echo "</div>\n <div id='error_delete_expense_invoice_" . $ex_invoice['lb_tax_id'] . "' class='alert alert-block alert-error' style='display:none;'></div>\n "; } // end for
public function actionCreateInvoice($id) { $model = LbContracts::model()->findByPk($id); //********* add new invoice *************/ $invoiceModel = new LbInvoice(); // get basic info to assign to this record $ownCompany = LbCustomer::model()->getOwnCompany(); $ownCompanyAddress = null; $customerCompany = new LbCustomer(); $customerCompany->lb_customer_name = 'Click to choose customer'; // get own company address if ($ownCompany->lb_record_primary_key) { // auto assign owner company $invoiceModel->lb_invoice_company_id = $ownCompany->lb_record_primary_key; $own_company_addresses = LbCustomerAddress::model()->getActiveAddresses($ownCompany->lb_record_primary_key, $ownCompany::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); if (count($own_company_addresses)) { $ownCompanyAddress = $own_company_addresses[0]; // auto assign owner company's address $invoiceModel->lb_invoice_company_address_id = $ownCompanyAddress->lb_record_primary_key; } } // add infor customer in invoice $invoiceModel->lb_invoice_customer_id = $model->lb_customer_id; $invoiceModel->lb_invoice_customer_address_id = $model->lb_address_id; $invoiceModel->lb_invoice_attention_contact_id = $model->lb_contact_id; if ($invoiceModel->save()) { // Save Lien ket contract va invoice $contrctInvoiceModel = new LbContractInvoice(); $contrctInvoiceModel->lb_contract_id = $model->lb_record_primary_key; $contrctInvoiceModel->lb_invoice_id = $invoiceModel->lb_record_primary_key; $contrctInvoiceModel->save(); //Update invoice no vaf status I-OPEN $invoiceModel->confirm(); // add invoice to database right away. // other fields will be updated on the invoice page later on $invoiceModel->saveUnconfirmed(); // // == Prepare line items grid // add 1 line-item by default // $blankItem = new LbInvoiceItem(); $blankItem->lb_invoice_id = $invoiceModel->lb_record_primary_key; $blankItem->lb_invoice_item_description = "Contract payment for contract " . $model->lb_contract_no . ", " . $model->lb_contract_type . ", for period " . $model->lb_contract_date_start . " to " . $model->lb_contract_date_end; $blankItem->lb_invoice_item_quantity = 1; $blankItem->lb_invoice_item_value = 0; $blankItem->lb_invoice_item_total = 0; $blankItem->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_LINE; $blankItem->save(); // add tax $blankTax = new LbInvoiceItem(); $default_tax = LbTax::model()->getDefaultTax(); //$value_tax = ($default_tax->lb_tax_value/100) * $model->lb_contract_amount; $blankTax->lb_invoice_id = $invoiceModel->lb_record_primary_key; $blankTax->lb_invoice_item_description = $default_tax !== null ? $default_tax->lb_record_primary_key : 'Tax'; $blankTax->lb_invoice_item_quantity = 1; $blankTax->lb_invoice_item_value = $default_tax !== null ? $default_tax->lb_tax_value : '0'; $blankTax->lb_invoice_item_total = 0; $blankTax->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_TAX; $blankTax->save(); $invoiceItemModel = new LbInvoiceItem('search'); $invoiceItemModel->unsetAttributes(); // clear any default values $invoiceItemModel->lb_invoice_id = $invoiceModel->lb_record_primary_key; // totals - create a blank total record, set everything to zero: subtotal, after disc, after tax, paid, outstanding.... $invoiceTotal = new LbInvoiceTotal(); $invoiceTotal->lb_invoice_id = $invoiceModel->lb_record_primary_key; $invoiceTotal->lb_invoice_revision_id = 0; // latest version $invoiceTotal->lb_invoice_subtotal = 0; $invoiceTotal->lb_invoice_total_after_discounts = 0; $invoiceTotal->lb_invoice_total_after_taxes = 0; $invoiceTotal->lb_invoice_total_outstanding = 0; $invoiceTotal->lb_invoice_total_paid = 0; $invoiceTotal->save(); // == end items grid data prep // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $invoiceDiscountModel = new LbInvoiceItem(); $invoiceDiscountModel->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_DISCOUNT; $invoiceTaxModel = new LbInvoiceItem(); $invoiceTaxModel->lb_invoice_item_type = LbInvoiceItem::LB_INVOICE_ITEM_TYPE_TAX; //*** End add invoice **/ //LBApplication::redire(array('lbInvoice/default/view','id'=>$invoiceModel->lb_record_primary_key)); $this->redirect(array('view', 'id' => $model->lb_record_primary_key)); } }
public function actionlist_item($list) { $taxModel = LbTax::model()->getTaxes(); if ($list == 'expenses_category') { $list_item = UserList::model()->getItemsListName($list); } // else $list_item = UserList::model()->getItemsListName($list); $this->render('list_item', array('list' => $list_item, 'list_name' => $list, 'taxModel' => $taxModel)); }