public function actionAjaxUpdateLineItems($id, $type) { $vendorItem = LbVendorItem::model()->getVendorItems($id, $type, LbVendorItem::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); if ($type == LbVendorItem::LB_VENDOR_INVOICE_ITEM_TYPE_LINE) { $return_type = LbVendorTotal::LB_VENDOR_INVOICE_TOTAL; $type_discount = LbVendorDiscount::LB_VENDOR_INVOICE_ITEM_TYPE_DISCOUNT; } if ($type == LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE) { $return_type = LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL; $type_discount = LbVendorDiscount::LB_VENDOR_ITEM_TYPE_DISCOUNT; } $subtotal = 0; foreach ($vendorItem as $item) { $item_id = $item->lb_record_primary_key; $item_value = $item->lb_vendor_item_price; $item_quantity = $item->lb_vendor_item_quantity; $item_description = $item->lb_vendor_item_description; // get POSTed values if (isset($_POST['lb_vendor_item_description' . $item_id])) { $item_description = $_POST['lb_vendor_item_description' . $item_id]; $item->lb_vendor_item_description = $item_description; } if (isset($_POST['lb_vendor_item_quantity' . $item_id])) { $item_quantity = $_POST['lb_vendor_item_quantity' . $item_id]; $item->lb_vendor_item_quantity = $item_quantity; } if (isset($_POST['lb_vendor_item_price' . $item_id])) { $item_value = $_POST['lb_vendor_item_price' . $item_id]; $item->lb_vendor_item_price = $item_value; } $item->lb_vendor_item_amount = $item_value * $item_quantity; $subtotal = $subtotal + $item_value * $item_quantity; // save $item->update(); } $total = LbVendorTotal::model()->calculateInvoiceSubTotal($id, $type, $return_type); LbVendorTotal::model()->totalAfterDiscount($id, $type_discount, $return_type); $vendorTotal = LbVendorTotal::model()->getVendorTotal($id, $return_type); LBApplication::renderPlain($this, array('content' => CJSON::encode($vendorTotal))); }
function actionAjaxCreateVendorInvoice($id) { $model = $this->loadModel($id); $quotationItem = LbVendorItem::model()->getVendorItems($id, LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE, LbVendorItem::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $quotationDiscount = LbVendorDiscount::model()->getVendorDiscounts($id, LbVendorDiscount::LB_VENDOR_ITEM_TYPE_DISCOUNT, LbVendorDiscount::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $quotationTax = LbVendorTax::model()->getTaxByVendor($id, LbVendorTax::LB_VENDOR_ITEM_TYPE_TAX, LbVendorTax::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $quotationTotal = LbVendorTotal::model()->getVendorTotal($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL); $invoiceModel = new LbVendorInvoice(); $invoice_number_int = LbVendorInvoice::model()->getVINextNum(); $invoiceModel->lb_vd_invoice_no = LbVendorInvoice::model()->formatVINextNumFormatted($invoice_number_int); $invoiceModel->lb_vd_invoice_status = LbVendorInvoice::LB_VD_CODE_OPEN; // invoice date $invoiceModel->lb_vd_invoice_date = date('Y-m-d'); $invoiceModel->lb_vd_invoice_due_date = date('Y-m-d'); // invoice group // $invoiceModel->lb_invoice_group = LbInvoice::LB_INVOICE_GROUP_INVOICE; // invoice base64_decode $invoiceModel->lb_vd_invoice_encode = LbVendorInvoice::model()->setBase64_decodePO(); // invoice note $invoiceModel->lb_vd_invoice_notes = $model->lb_vendor_notes; $invoiceModel->lb_vd_invoice_company_id = $model->lb_vendor_company_id; $invoiceModel->lb_vd_invoice_company_address_id = $model->lb_vendor_company_address_id; $invoiceModel->lb_vd_invoice_supplier_id = $model->lb_vendor_supplier_id; $invoiceModel->lb_vd_invoice_supplier_address_id = $model->lb_vendor_supplier_address; $invoiceModel->lb_vd_invoice_supplier_attention_id = $model->lb_vendor_supplier_attention_id; $invoiceModel->lb_vendor_id = $model->lb_record_primary_key; $invoiceModel->lb_vd_invoice_subject = $model->lb_vendor_subject; $invoiceModel->lb_vd_invoice_category = $model->lb_vendor_category; // invoice internal note // $invoiceModel->lb_invoice_internal_note = $model->lb_quotation_internal_note; if ($invoiceModel->insert()) { // copy line item foreach ($quotationItem as $q_item) { $vendorItem = new LbVendorItem(); $vendorItem->lb_vendor_id = $id; $vendorItem->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key; $vendorItem->lb_vendor_type = LbVendorItem::LB_VENDOR_INVOICE_ITEM_TYPE_LINE; $vendorItem->lb_vendor_item_quantity = $q_item->lb_vendor_item_quantity; $vendorItem->lb_vendor_item_price = $q_item->lb_vendor_item_price; $vendorItem->lb_vendor_item_amount = $q_item->lb_vendor_item_amount; $vendorItem->lb_vendor_item_description = $q_item->lb_vendor_item_description; $vendorItem->insert(); } // copy tax item foreach ($quotationTax as $q_tax) { $taxInvoiceVendor = new LbVendorTax(); $taxInvoiceVendor->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key; $taxInvoiceVendor->lb_vendor_id = $id; $taxInvoiceVendor->lb_vendor_type = LbVendorTax::LB_VENDOR_INVOICE_ITEM_TYPE_TAX; $taxInvoiceVendor->lb_vendor_tax_id = $q_tax->lb_vendor_tax_id; $taxInvoiceVendor->lb_tax_name = $q_tax->lb_tax_name; $taxInvoiceVendor->lb_vendor_tax_value = $q_tax->lb_vendor_tax_value; $taxInvoiceVendor->lb_vendor_tax_total = $q_tax->lb_vendor_tax_total; $taxInvoiceVendor->insert(); } // // // copy discount item foreach ($quotationDiscount as $q_discount) { $discountVendorInvoice = new LbVendorDiscount(); $discountVendorInvoice->lb_vendor_id = $id; $discountVendorInvoice->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key; $discountVendorInvoice->lb_vendor_description = $q_discount->lb_vendor_description; $discountVendorInvoice->lb_vendor_value = $q_discount->lb_vendor_value; $discountVendorInvoice->lb_vendor_type = LbVendorDiscount::LB_VENDOR_INVOICE_ITEM_TYPE_DISCOUNT; $discountVendorInvoice->insert(); } // // // Copy Total $vendorItem = new LbVendorTotal(); $vendorItem->lb_vendor_invoice_id = $invoiceModel->lb_record_primary_key; $vendorItem->lb_vendor_id = $id; $vendorItem->lb_vendor_type = LbVendorTotal::LB_VENDOR_INVOICE_TOTAL; $vendorItem->lb_vendor_subtotal = $quotationTotal->lb_vendor_subtotal; $vendorItem->lb_vendor_total_last_discount = $quotationTotal->lb_vendor_total_last_discount; $vendorItem->lb_vendor_last_tax = $quotationTotal->lb_vendor_last_tax; $vendorItem->lb_vendor_last_paid = $quotationTotal->lb_vendor_last_paid; $vendorItem->lb_vendor_last_outstanding = $quotationTotal->lb_vendor_last_outstanding; $vendorItem->insert(); // redirect Invoice // $url_invoice = $model->customer ? LbInvoice::model()->getViewURL($model->customer->lb_customer_name,null,$invoiceModel->lb_record_primary_key) : LbInvoice::model()->getViewURL("No customer",null,$invoiceModel->lb_record_primary_key); // $this->redirect($url_invoice); } }
//$canDeleteAll = BasicPermission::model()->checkModules($m, 'delete all'); //LbVendorItem::model()->addLineItemVendor($model->lb_record_primary_key, 'LINE'); $currency_name = LbGenera::model()->getGeneraSubscription()->lb_genera_currency_symbol; /******************************************************************************** * ============================= LINE ITEMS SECTION ============================= *******************************************************************************/ echo '<div id="container-invoice-line-items-section" style="margin-top: 30px">'; $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'lb-invoice-items-form', 'enableAjaxValidation' => false, 'type' => 'horizontal')); /** LineItem Grid's $data is LbInvoiceItem Each line item's fields (description, quantity, unit price and total) are marked by the line item's primary key. */ $itemVendor = $modelItemVendor->getItemByVendor($model->lb_record_primary_key, LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE); //echo $itemVendor->lb_vendor_id; $itemLineVendor = LbVendorItem::model()->find('lb_vendor_id = ' . $model->lb_record_primary_key . ' AND lb_vendor_type = "LINE"'); //if(count($itemLineVendor) == 0) //{ // $itemManage = new LbVendorItem(); // // $itemManage->addLineItemVendor($model->lb_record_primary_key,LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE); //// LbVendorTotal::model()->addTotalVendor($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL); // //} $modelTotal = LbVendorTotal::model()->getVendorTotal($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL); $grid_id = 'invoice-line-items-grid-' . $model->lb_record_primary_key; $this->widget('bootstrap.widgets.TbGridView', array('id' => $grid_id, 'dataProvider' => $modelItemVendor->getItemByVendor($model->lb_record_primary_key, LbVendorItem::LB_VENDOR_ITEM_TYPE_LINE), 'columns' => array(array('header' => '#', 'type' => 'raw', 'value' => '1', 'htmlOptions' => array('style' => 'width: 10px; '), 'headerHtmlOptions' => array('class' => 'lb-grid-header')), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => "{delete}", 'deleteButtonUrl' => '"' . $model->getActionURLNormalized("ajaxDeleteItem") . '" . "?id={$data->lb_record_primary_key}"', 'afterDelete' => 'function(link,success,data){ if(success) { refreshTotals(); refreshTaxesGrid();
if ($model->lb_vendor_category) { $list_name = SystemList::model()->findByPk($model->lb_vendor_category)['system_list_item_code']; } $tbody = '<table border="0" style="width:100%;" cellpadding="0" cellspacing="0">'; $tbody .= '<tr>' . '<td style="width:100px;"><b>To: </b> </td><td>' . $customerName . '</td>' . '</tr><br />'; $tbody .= '<tr>' . '<td><b>Billing Address: </b></td><td>' . $billingName . '</td>' . '</tr>'; $tbody .= '<tr>' . '<td><b>Attention: </b></td><td>' . $attentionInformation . '</td>' . '</tr>'; $tbody .= '<tr>' . '<td><b>Category: </b></td><td>' . $list_name . '</td>' . '</tr>'; $tbody .= '<tr>' . '<td><b>Subject:</b></td><td>' . $model->lb_vendor_subject . '</td></tr>'; $tbody .= '</table>'; echo $tbody; echo '<br>'; echo '<br>'; echo '<br>'; //Item $modelItem = LbVendorItem::model()->findAll('lb_vendor_id=55'); if (count($modelItem) > 0) { $tItem = '<table border="1" style="width:100%;" cellpadding="0" cellspacing="0">'; $tItem .= '<tr>' . '<td style="width:200px;height:30px">Item</td>' . '<td style="width:100px;">Quantity</td>' . '<td style="width:200px;">Price</td>' . '<td style="width:200px;">Total</td>' . '</tr>'; foreach ($modelItem as $dataItem) { $tItem .= '<tr>' . '<td style="height:15px">' . $dataItem['lb_vendor_item_description'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_quantity'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_price'] . '</td>' . '<td>' . $dataItem['lb_vendor_item_amount'] . '</td>' . '</tr>'; } $tItem .= '</table>'; echo $tItem . '<br />'; } //Total $modelTotal = LbVendorTotal::model()->getVendorTotal($model->lb_record_primary_key, LbVendorTotal::LB_VENDOR_ITEM_TYPE_TOTAL); //Discount $discountItem = '<table border="0" style="width:100%;" cellpadding="0" cellspacing="0">'; $discountItem .= '<tr>' . '<td style="width:100px;"><b>Sub Total : </b></td>' . '<td style="border-bottom:1px solid black">$' . $modelTotal->lb_vendor_subtotal . '</td>' . '</tr>'; $discountAll = LbVendorDiscount::model()->findAll('lb_vendor_id = ' . $model->lb_record_primary_key);
public function calculateInvoiceSubTotal($id, $type, $return_type) { // get invoice items $total = new LbVendorTotal(); $invoice_line_items = LbVendorItem::model()->getVendorItems($id, $type, LbVendorItem::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); // calculate sub total $subtotal = 0; foreach ($invoice_line_items as $item) { $subtotal += $item->lb_vendor_item_amount; } $id = $this->getIdVendorTotalByItem($id, $return_type); // $total = LbVendorTotal::model()->findByPk($id); $total->lb_vendor_subtotal = $subtotal; $total->update(); // }