public function addSupplier() { $this->lb_vd_invoice_no = 0; $this->lb_vd_invoice_no = $this->formatNumberNextNumFormatted($this->lb_vd_invoice_no); $this->lb_vd_invoice_date = date('Y-m-d'); $this->lb_vd_invoice_due_date = date('Y-m-d'); $this->lb_vd_invoice_status = self::LB_VD_STATUS_CODE_DRAFT; $this->lb_vd_invoice_encode = $this->setBase64_decodePO(); $this->lb_vd_invoice_notes = ''; $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 $this->lb_vd_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 $this->lb_vd_invoice_company_address_id = $ownCompanyAddress->lb_record_primary_key; } } if ($this->insert()) { return $this->lb_record_primary_key; } return false; }
public function savePaymentVoucher($pv_no = false, $pv_title = false, $pv_date = false, $pv_description = false, $pv_id = false) { $model = new LbPaymentVoucher(); //company $ownCompany = LbCustomer::model()->getOwnCompany(); $ownCompanyAddress = null; if ($ownCompany->lb_record_primary_key) { // auto assign owner company $model->lb_pv_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 $model->lb_pv_company_address_id = $ownCompanyAddress->lb_record_primary_key; } } if ($pv_id) { $model = LbPaymentVoucher::model()->findByPk($pv_id); } if ($pv_no) { $model->lb_payment_voucher_no = $pv_no; } if ($pv_title) { $model->lb_pv_title = $pv_title; } if ($pv_date) { $model->lb_pv_date = DateTime::createFromFormat('d-m-Y', $pv_date)->format('Y-m-d'); } if ($pv_date) { $model->lb_pv_description = $pv_description; } $model->lb_pv_create_by = Yii::app()->user->id; if ($pv_id) { $model->update(); return $pv_id; } if ($model->insert()) { return $model->lb_record_primary_key; } }
$m = $this->module->id; $canAdd = BasicPermission::model()->checkModules($m, 'add'); $canView = BasicPermission::model()->checkModules($m, 'view'); $canAddInvoice = BasicPermission::model()->checkModules(LbInvoice::model()->getEntityType(), 'add'); if (!$canView) { echo "Have no permission to see this record"; return; } echo '<div id="lb-container-header">'; echo '<div class="lb-header-right" style="margin-left:-11px;"><h3>' . Yii::t('lang', 'Customers') . '</h3></div>'; echo '<div class="lb-header-left">'; LBApplicationUI::backButton($model->getHomeURLNormalized()); echo ' '; // new if ($canAdd || $canAddInvoice) { LBApplicationUI::newButtonGroup(Yii::t('lang', 'New'), array('buttons' => array(array('items' => array(array('label' => Yii::t('lang', 'New Address'), 'url' => LbCustomerAddress::model()->getCreateURLNormalized(array('customer_id' => $model->lb_record_primary_key)), 'visible' => $canAdd), array('label' => Yii::t('lang', 'New Contact'), 'url' => LbCustomerContact::model()->getCreateURLNormalized(array('customer_id' => $model->lb_record_primary_key)), 'visible' => $canAdd), array('label' => Yii::t('lang', 'New Invoice'), 'url' => '#', 'visible' => $canAddInvoice), '---', array('label' => Yii::t('lang', 'New Customer'), 'url' => $model->getCreateURLNormalized(), 'visible' => $canAdd)))))); } echo '</div>'; echo '</div>'; ?> <div style="width:30%;margin-top:19px;margin-bottom:11px;"><span style="font-size: 16px;"><b><?php echo $model->lb_customer_name; ?> </b></span></div> <?php echo '<div class="btn-toolbar">'; // go back /** LBApplicationUI::newButton('New Address');
onChangeCustomerDropdown(e,' . $model->lb_record_primary_key . '); }); }', 'htmlOptions' => array('id' => 'LbInvoice_invoice_customer_id_' . $model->lb_record_primary_key))); echo '</div>'; // end div for customer name's txt echo CHtml::hiddenField('hidden-invoice-customer-id', $model->lb_vd_invoice_supplier_id, array('id' => 'hidden-invoice-customer-id')); echo '</div>'; // end customer name // // customer address echo '<div id="container-invoice-customer-address">'; echo '<div class="field-label-left">' . Yii::t('lang', 'Address') . ':</div>'; echo '<div class="field-value-left lb_info_bill">'; $this->widget('editable.EditableField', array('type' => 'select', 'model' => $model, 'attribute' => 'lb_vd_invoice_supplier_address_id', 'emptytext' => 'Choose billing address', 'url' => lbvendor::model()->getActionURLNormalized('ajaxUpdateFieldInvoice'), 'source' => $this->createUrl('/lbCustomerAddress/default/dropdownJSON', array('allow_add' => 2, 'lb_vendor_invoice_id' => $model->lb_record_primary_key)), 'placement' => 'right', 'display' => 'js: function(value, sourceData) { var el = $(this); $.get("' . LbCustomerAddress::model()->getActionURLNormalized('addressLinesJSON') . '?id="+value,function(response){ var jsonResponse = jQuery.parseJSON(response); updateInvoiceAddressLines(jsonResponse); }); }', 'validate' => 'function(value){ if (value < 0) return "Please select a valid address"; }', 'options' => array('sourceCache' => false), 'htmlOptions' => array('id' => 'LbInvoice_invoice_customer_address_id_' . $model->lb_record_primary_key), 'onShown' => 'js: function() { var $tip = $(this).data("editableContainer").tip(); var dropdown = $tip.find("select"); $(dropdown).bind("change", function(e){ onChangeAddressDropdown(e,' . $model->lb_record_primary_key . '); }); }')); echo '</div>'; echo '</div>'; // end customer address
<?php /* @var $customer_addresses array of LbCustomerAddress models */ $canDeleteAddress = BasicPermission::model()->checkModules(LbCustomerAddress::model()->getEntityType(), 'delete'); $canEditAddress = BasicPermission::model()->checkModules(LbCustomerAddress::model()->getEntityType(), 'edit'); $i = 0; foreach ($customer_addresses as $address) { $i++; echo "\r\n <div style='overflow:hidden; border-top: 1px solid #EEEEEE;margin-top: 5px;'>\r\n <div style='float:left'>\r\n <h4><span style='padding: 0 8px;background:#EEEEEE;border-radius:50%;'>{$i}</span> {$address->lb_customer_address_line_1}</h4>\r\n </div>\r\n <div style='float:right;margin-top:5px;'>\r\n <a href='#' onclick=\"onclickSlideToggle(" . $address->lb_record_primary_key . "); return false;\">\r\n <i class='icon-info-sign'></i>\r\n " . Yii::t('lang', 'Detail information') . "\r\n </a>"; if ($canDeleteAddress) { echo "<a href='#' onclick='ajaxDeleteAddress(" . $address->lb_record_primary_key . "); return false;'>\r\n <i class='icon-trash'></i>\r\n " . Yii::t('lang', 'Delete') . "\r\n </a>"; } echo "</div>\r\n </div>\r\n <div id='error_delete_address_" . $address->lb_record_primary_key . "' class='alert alert-block alert-error' style='display:none;'></div>\r\n "; echo "<div id='detail_customer_address_" . $address->lb_record_primary_key . "' style='display:none;'>"; $this->widget('editable.EditableDetailView', array('data' => $address, 'url' => $address->getActionURL('ajaxUpdateField'), 'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken), 'attributes' => array(array('name' => 'lb_customer_address_line_1', 'editable' => array('type' => 'text', 'inputclass' => 'input-large', 'emptytext' => 'Click to Update', 'validate' => 'function(value) { if(!value) return "Address Line 1 is required." }')), 'lb_customer_address_line_2', 'lb_customer_address_city', 'lb_customer_address_state', array('name' => 'lb_customer_address_country', 'editable' => array('type' => 'select', 'source' => LBApplicationUI::countriesDropdownData(), 'placement' => 'right')), 'lb_customer_address_postal_code', 'lb_customer_address_website_url', 'lb_customer_address_phone_1', 'lb_customer_address_phone_2', 'lb_customer_address_fax', 'lb_customer_address_email', 'lb_customer_address_note', array('name' => 'lb_customer_address_is_active', 'editable' => array('type' => 'select', 'source' => LbCustomerAddress::$dropdownActive, 'placement' => 'right'))))); echo "</div>"; } // end for ?> <script> function onclickSlideToggle(id) { $("#detail_customer_address_"+id).slideToggle(); $("#error_delete_address_"+id).css("display","none"); } function ajaxDeleteAddress(id) { $.ajax({
public function actioncreatePo() { $model = new LbVendor(); // 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 $model->lb_vendor_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 $model->lb_vendor_company_address_id = $ownCompanyAddress->lb_record_primary_key; } } if ($model->save()) { $id = $_GET['id']; $invoiceVendor = LbVendorInvoice::model()->findByPk($id); $invoiceVendor->lb_vendor_id = $model->lb_record_primary_key; $invoiceVendor->save(); $this->redirect(array('view', 'id' => $model->lb_record_primary_key)); } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return LbCustomerAddress the loaded model * @throws CHttpException */ public function loadModel($id) { $model = LbCustomerAddress::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
</tr> <tr> <td><b>Status: </b>' . $model->lb_vendor_status . '</td> </tr> </table> '; echo $tbl; $customerName = false; if ($model->lb_vendor_supplier_id) { $customerName = LbCustomer::model()->findByPk($model->lb_vendor_supplier_id)['lb_customer_name']; } $billingName = false; if ($model->lb_vendor_supplier_address) { $informationAdd = LbCustomerAddress::model()->findByPk($model->lb_vendor_supplier_address); $billingName = $informationAdd['lb_customer_address_line_1'] . '. ' . $informationAdd['lb_customer_address_line_2'] . '<br />'; // $billingName .=$informationAdd['lb_customer_address_postal_code'].'<br>'; // $billingName .=$informationAdd['lb_customer_address_website_url'].'<br>'; } $attentionInformation = false; if ($model->lb_vendor_supplier_attention_id) { $attention = LbCustomerContact::model()->findByPk($model->lb_vendor_supplier_attention_id); $attentionInformation = $attention['lb_customer_contact_first_name'] . ' ' . $attention['lb_customer_contact_last_name']; } $list_name = false; 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 />';
public function actionAjaxDropDownAddress() { $customer_id = $_POST['customer_id_statement']; $option_address = '<option value="0">All</option>'; $address_arr = LbCustomerAddress::model()->getAddresses($customer_id, LbCustomer::LB_QUERY_RETURN_TYPE_DROPDOWN_ARRAY); foreach ($address_arr as $key => $value) { $option_address .= '<option value="' . $key . '">' . $value . '</option>'; } echo $option_address; }
// 'value'=> number_format($model->lb_contract_amount, 2), // ) //// 'lb_customer_id', //// 'lb_address_id', //// 'lb_contact_id', //// 'lb_contract_no', //// 'lb_contract_notes', //// 'lb_contract_date_start', //// 'lb_contract_date_end', //// 'lb_contract_type', //// 'lb_contract_amount', //// 'lb_contract_parent', //// 'lb_contract_status', // ), //)); $this->widget('editable.EditableDetailView', array('id' => 'user-details', 'data' => $model, 'url' => $model->getActionURL('ajaxUpdateField'), 'placement' => 'right', 'attributes' => array(array('name' => 'lb_customer_id', 'editable' => array('type' => 'select', 'source' => CHtml::listData(LbCustomer::model()->findAll(), 'lb_record_primary_key', 'lb_customer_name'))), array('name' => 'lb_address_id', 'editable' => array('type' => 'select', 'source' => CHtml::listData(LbCustomerAddress::model()->findAll(), 'lb_record_primary_key', 'lb_customer_address_line_1'))), array('name' => 'lb_contact_id', 'editable' => array('type' => 'select', 'source' => CHtml::listData(LbCustomerContact::model()->getResultsAsFindAll(), 'lb_record_primary_key', 'lb_customer_contract_name'))), array('name' => 'lb_contract_date_start', 'editable' => array('type' => 'date', 'viewformat' => 'dd-mm-yyyy', 'format' => 'yyyy-mm-dd')), array('name' => 'lb_contract_date_end', 'editable' => array('type' => 'date', 'viewformat' => 'dd-mm-yyyy', 'format' => 'yyyy-mm-dd')), array('name' => 'lb_contract_type', 'editable' => array('type' => 'text')), array('name' => 'lb_contract_notes', 'editable' => array('type' => 'textarea')), array('name' => 'lb_contract_status', 'editable' => array('type' => 'select', 'source' => LbContracts::$ContractStatusArray)), 'lb_contract_amount'))); ?> <div style="margin-top: 30px;"> <h4><?php echo Yii::t('lang', 'Document'); ?> </h4> <?php $this->widget('bootstrap.widgets.TbGridView', array('id' => 'lb-contracts-documnet_grid', 'dataProvider' => LbContractDocument::model()->getContractDocument($model->lb_record_primary_key), 'template' => '{items}', 'hideHeader' => true, 'htmlOptions' => array('width' => '500'), 'columns' => array(array('type' => 'raw', 'value' => '"<a href=\'".Yii::app()->getBaseUrl().$data->lb_document_url."\'><img border=\'0\' alt=\'\' src=\'".Yii::app()->getBaseUrl().$data->lb_document_url_icon."\' />".$data->lb_document_name."</a>"'), array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => "{delete}", 'deleteButtonUrl' => 'Yii::app()->createUrl("lbContract/default/deleteDocument",array("id"=>$data->lb_record_primary_key))', 'htmlOptions' => array('width' => '20'))))); ?> <div> <?php if ($canEdit) { $this->widget('ext.EAjaxUpload.EAjaxUpload', array('id' => 'uploadFile', 'config' => array('action' => $this->createUrl('uploadDocument', array('id' => $model->lb_record_primary_key)), 'allowedExtensions' => array("jpeg", "jpg", "gif", "png", "pdf", "odt", "docx", "doc", "dia"), 'sizeLimit' => 10 * 1024 * 1024, 'minSizeLimit' => 1 * 1024, 'onComplete' => "js:function(id, fileName, responseJSON){\n \$.fn.yiiGridView.update('lb-contracts-documnet_grid');\n \$('#uploadFile .qq-upload-list').html('');\n }"))); } ?>
function tableSearch($customer_id_statements = false, $attention_statement = false, $address_option = false, $status = false, $date_from = false, $date_to = false) { $outstanding = 0; $paid = 0; $tax = 0; global $valuePaid; global $valueAmount; global $valueDue; $StatementSearch = LbInvoice::model()->getInvoiceStatement($customer_id_statements, $_POST['attention_statement'], $address_option, $status, $date_from, $date_to); // $addName = LbCustomerAddress::model()->find('lb_record_primary_key='.$address_option); // echo '<span style="font-size: 16px;"><b>Address: </b>'.$addName->lb_customer_address_line_1.'</span><br />'; if (count($StatementSearch) > 0) { if (isset($address_option)) { $addName = LbCustomerAddress::model()->find('lb_record_primary_key=' . $address_option); } echo '<span style="font-size: 16px;"><b>Address: </b>' . $addName->lb_customer_address_line_1 . '</span><br />'; echo ' <table border="0" width="100%" class="items table table-bordered"> <thead> <tr> <th width="250" class="lb-grid-header">' . Yii::t('lang', 'Date') . '</th> <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Invoice Number') . '</th> <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Amount') . '</th> <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Payments') . '</th> <th width="150" class="lb-grid-header">' . Yii::t('lang', 'Due') . '</th> </tr> </thead> <tbody>'; foreach ($StatementSearch as $data) { $getInvoiceById = LbInvoiceTotal::model()->getInvoiceById($data['lb_record_primary_key']); $addArr = LbInvoice::model()->findAll('lb_invoice_customer_address_id=' . $data['lb_invoice_customer_address_id']); $outstanding = $outstanding + $getInvoiceById['lb_invoice_total_outstanding']; $paid = $paid + $getInvoiceById['lb_invoice_total_paid']; $tax = $tax + $getInvoiceById['lb_invoice_total_after_taxes']; echo '<tr>'; echo '<td>' . $data['lb_invoice_date'] . '</td>'; echo '<td>' . $data['lb_invoice_no'] . '</td>'; echo '<td>' . $getInvoiceById['lb_invoice_total_after_taxes'] . '</td>'; echo '<td>' . $getInvoiceById['lb_invoice_total_paid'] . '</td>'; echo '<td>' . $getInvoiceById['lb_invoice_total_outstanding'] . '</td>'; echo '</tr>'; $valuePaid = $valuePaid + $getInvoiceById['lb_invoice_total_paid']; $valueAmount = $valueAmount + $getInvoiceById['lb_invoice_total_after_taxes']; $valueDue = $valueDue + $getInvoiceById['lb_invoice_total_outstanding']; } echo '</tbody>' . '<tfoot>'; echo '<tr>'; echo '<td></td>'; echo '<td></td>'; echo '<td style="border-top:1px solid #000" ><b>$' . number_format($tax, 2) . '</b></td>'; echo '<td style="border-top:1px solid #000"><b>$' . number_format($paid, 2) . '<b></td>'; echo '<td style="border-top:1px solid #000"><b>$' . number_format($outstanding, 2) . '</b></td>'; echo '</tr>' . '</tfoot>' . '</table>'; } }
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)); } }
/** * Use for updating through inline editable * such as jquery editable, bootstrap x-editable, etc. * * POST params * pk the primary key of this record * name attribute name * value value to be updated to * * This action actually call actionAjaxUpdateField in parent controller * , but also continue to auto assign address to this quotation. */ function actionAjaxUpdateCustomer() { if ($this->actionAjaxUpdateField()) { $quotation_id = $_POST['pk']; $quotation = LbQuotation::model()->findByPk($quotation_id); if ($quotation) { // reset address just in case some address of previous customer is already there $quotation->lb_quotation_customer_address_id = 0; $quotation->lb_quotation_attention_id = 0; $address_array['customer_name'] = ""; $quotation->save(); $address_array['customer'] = $quotation->lb_quotation_customer_id; if ($quotation->lb_quotation_customer_id > 0) { $custoemr_name = str_replace(' ', '-', $quotation->customer->lb_customer_name); $address_array['customer_name'] = $custoemr_name; } // auto assign one of the addresses of this customer to this invoice $addresses = LbCustomerAddress::model()->getAddresses($quotation->lb_quotation_customer_id, LbCustomerAddress::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $firstAddress = null; if (count($addresses)) { // get first billing address // or just first address to auto assign to this invoice $firstAddress = $addresses[0]; // be default, just use first address foreach ($addresses as $addr) { // if billing address, use this instead if ($addr->lb_customer_address_is_billing) { $firstAddress = $addr; break; // no need to carry on } // assign address to invoice $quotation->lb_quotation_customer_address_id = $firstAddress->lb_record_primary_key; if ($quotation->save()) { // return that address in json // we need to format it nicely. $address_array = $firstAddress->formatAddressLines(); $address_array['customer_name'] = ""; $address_array['customer'] = $quotation->lb_quotation_customer_id; if ($quotation->lb_quotation_customer_id > 0) { $custoemr_name = str_replace(' ', '-', $quotation->customer->lb_customer_name); $address_array['customer_name'] = $custoemr_name; } // print json // LBApplication::renderPartial($this, '//layouts/plain_ajax_content', array( // 'content'=>CJSON::encode($address_array), // )); } // end formatting address to return in json } } LBApplication::renderPartial($this, '//layouts/plain_ajax_content', array('content' => CJSON::encode($address_array))); return true; } } }
public function actionajaxUpdateCustomerVI() { if ($this->actionAjaxUpdateFieldInvoice()) { $vendor_id = $_POST['pk']; $vendor = LbVendorInvoice::model()->findByPk($vendor_id); if ($vendor) { // reset address just in case some address of previous customer is already there $vendor->lb_vd_invoice_supplier_id = $_POST['value']; $vendor->lb_vd_invoice_supplier_attention_id = 0; $vendor->save(); // auto assign one of the addresses of this customer to this invoice $addresses = LbCustomerAddress::model()->getAddresses($vendor->lb_vd_invoice_supplier_id, LbCustomerAddress::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $firstAddress = null; // only proceed if found any address if (count($addresses)) { // get first billing address // echo // or just first address to auto assign to this invoice $firstAddress = $addresses[0]; // be default, just use first address foreach ($addresses as $addr) { // if billing address, use this instead if ($addr->lb_customer_address_is_billing) { $firstAddress = $addr; break; // no need to carry on } } // assign address to invoice $vendor->lb_vd_invoice_supplier_address_id = $firstAddress->lb_record_primary_key; if ($vendor->save()) { // return that address in json // we need to format it nicely. $address_array = $firstAddress->formatAddressLines(); // print json LBApplication::renderPartial($this, '//layouts/plain_ajax_content', array('content' => CJSON::encode($address_array))); return true; } // end formatting address to return in json } // end if found addresses } return true; } return false; }
/** * Use for updating through inline editable * such as jquery editable, bootstrap x-editable, etc. * * POST params * pk the primary key of this record * name attribute name * value value to be updated to * * This action actually call actionAjaxUpdateField in parent controller * , but also continue to auto assign address to this invoice. */ public function actionAjaxUpdateCustomer() { // call ajaxUpdateField to update customer id if ($this->actionAjaxUpdateField()) { // updated invoice_customer_id successfully // now find this customer address and auto assign // the first billing address we found // or if no billing address found, just assign first address $invoice_id = $_POST['pk']; $invoice = LbInvoice::model()->findByPk($invoice_id); if ($invoice) { // reset address just in case some address of previous customer is already there $invoice->lb_invoice_customer_address_id = 0; $invoice->lb_invoice_attention_contact_id = 0; $invoice->save(); $address_array['customer'] = $invoice->lb_invoice_customer_id; if ($invoice->lb_invoice_customer_id > 0) { $custoemr_name = str_replace(' ', '-', $invoice->customer->lb_customer_name); $address_array['customer_name'] = $custoemr_name; } // auto assign one of the addresses of this customer to this invoice $addresses = LbCustomerAddress::model()->getAddresses($invoice->lb_invoice_customer_id, LbCustomerAddress::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); $firstAddress = null; // only proceed if found any address if (count($addresses)) { // get first billing address // or just first address to auto assign to this invoice $firstAddress = $addresses[0]; // be default, just use first address foreach ($addresses as $addr) { // if billing address, use this instead if ($addr->lb_customer_address_is_billing) { $firstAddress = $addr; break; // no need to carry on } } // assign address to invoice $invoice->lb_invoice_customer_address_id = $firstAddress->lb_record_primary_key; if ($invoice->save()) { // return that address in json // we need to format it nicely. $address_array = $firstAddress->formatAddressLines(); $address_array['customer'] = $invoice->lb_invoice_customer_id; if ($invoice->lb_invoice_customer_id > 0) { $custoemr_name = str_replace(' ', '-', $invoice->customer->lb_customer_name); $address_array['customer_name'] = $custoemr_name; } // print json } // end formatting address to return in json } // end if found addresses } LBApplication::renderPartial($this, '//layouts/plain_ajax_content', array('content' => CJSON::encode($address_array))); return true; } return false; }
function ActionLoadAjaxTabAddress($id) { $customer_addresses = LbCustomerAddress::model()->getAddresses($id, LbCustomerAddress::LB_QUERY_RETURN_TYPE_MODELS_ARRAY); LBApplication::renderPartial($this, '_customer_addresses', array('customer_addresses' => $customer_addresses, 'customer_id' => $id)); }
</tr> <tr> </tr> </table> '; echo $tbl; //information payment voucher $add = ""; $modelCustomer = LbCustomer::model()->find('lb_record_primary_key=' . $model->lb_pv_company_id); $modelAddress = LbCustomerAddress::model()->find('lb_record_primary_key = ' . $model->lb_pv_company_address_id); if (isset($modelAddress->lb_customer_address_line_1) || isset($modelAddress->lb_customer_address_line_2)) { $add = 'Address: '; } $tblPV = '<table border="0" style="margin:auto;width:100%;" cellpadding="0" cellspacing="0"> ' . $html_logo . ' <tr valign="top"> <td width="300"> <span style="font-size:20px;font-weight:bold;">PAYMENT VOUCHER</span><br> Payment Voucher No: ' . $model->lb_payment_voucher_no . '<br> Payment Voucher Date: ' . date('d-M-Y', strtotime($model->lb_pv_date)) . '<br> Title : ' . $model->lb_pv_title . '<br /> Description : ' . $model->lb_pv_description . '<br /> Create By : ' . AccountProfile::model()->getFullName($model->lb_pv_create_by) . '<br /> </td>