Esempio n. 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     // are we creating invoice or quotation?
     if (isset($_GET['group']) && $_GET['group'] == strtolower(LbInvoiceGeneric::LB_INVOICE_GROUP_INVOICE)) {
         $model = new LbInvoice();
     } else {
         $model = new LbQuotation();
     }
     // 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_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
             $model->lb_invoice_company_address_id = $ownCompanyAddress->lb_record_primary_key;
         }
     }
     // add invoice to database right away.
     // other fields will be updated on the invoice page later on
     $model->saveUnconfirmed();
     //
     // == Prepare line items grid
     // add 1 line-item by default
     //
     $blankItem = new LbInvoiceItem();
     $blankItem->addBlankItem($model->lb_record_primary_key);
     $blankTax = new LbInvoiceItem();
     $blankTax->addBlankTax($model->lb_record_primary_key);
     $invoiceItemModel = new LbInvoiceItem('search');
     $invoiceItemModel->unsetAttributes();
     // clear any default values
     $invoiceItemModel->lb_invoice_id = $model->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->createBlankTotal($model->lb_record_primary_key);
     // == 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;
     if (isset($_POST['LbInvoice'])) {
         $model->attributes = $_POST['LbInvoice'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
         }
     }
     $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
     /**
     		LBApplication::render($this,'create',array(
     			//'save_unconfirmed'=>$save_unconfirmed,
     			'model'=>$model,
     			'invoiceItemModel'=>$invoiceItemModel,
                 'invoiceDiscountModel'=>$invoiceDiscountModel,
                 'invoiceTaxModel'=>$invoiceTaxModel,
                 'invoiceTotal'=>$invoiceTotal,
     		));**/
     /**
             LBApplication::render($this,'view',array(
                 'model'=>$model,
                 'invoiceItemModel'=>$invoiceItemModel,
                 'invoiceDiscountModel'=>$invoiceDiscountModel,
                 'invoiceTaxModel'=>$invoiceTaxModel,
                 'invoiceTotal'=>$invoiceTotal,
             ));**/
 }
Esempio n. 2
0
 public function actionAjaxCopyQuotation($id)
 {
     //Add thong tin quotation
     $quo_new = new LbQuotation();
     $quotation = LbQuotation::model()->findByPk($id);
     $quo_new->lb_quotation_no = LbQuotation::model()->formatQuotationNextNumFormatted(0);
     $quo_new->lb_quotation_date = date('Y-m-d');
     $quo_new->lb_quotation_due_date = date('Y-m-d');
     $quo_new->lb_quotation_status = LbQuotation::LB_QUOTATION_STATUS_CODE_DRAFT;
     $quo_new->lb_company_id = $quotation->lb_company_id;
     $quo_new->lb_company_address_id = $quotation->lb_company_address_id;
     $quo_new->lb_quotation_customer_id = $quotation->lb_quotation_customer_id;
     $quo_new->lb_quotation_customer_address_id = $quotation->lb_quotation_customer_address_id;
     $quo_new->lb_quotation_attention_id = $quotation->lb_quotation_attention_id;
     $quo_new->lb_quotation_internal_note = $quotation->lb_quotation_internal_note;
     $quo_new->lb_quotation_subject = $quotation->lb_quotation_subject;
     $quo_new->lb_quotation_note = $quotation->lb_quotation_note;
     $quo_new->lb_quotation_encode = LbQuotation::model()->setBase64_decodeQuotation();
     if ($quo_new->save()) {
         // Add thong tin tax
         $quotation_tax_arr = LbQuotationTax::model()->getTaxQuotation($quotation->lb_record_primary_key);
         foreach ($quotation_tax_arr->data as $tax_item) {
             $quo_tax_new = new LbQuotationTax();
             $quo_tax_new->lb_quotation_id = $quo_new->lb_record_primary_key;
             $quo_tax_new->lb_quotation_tax_id = $tax_item->lb_quotation_tax_id;
             $quo_tax_new->lb_quotation_tax_value = $tax_item->lb_quotation_tax_value;
             $quo_tax_new->lb_quotation_tax_total = $tax_item->lb_quotation_tax_total;
             $quo_tax_new->save();
         }
         //END
         //Add thong tin discount
         $quotation_discount_arr = LbQuotationDiscount::model()->getQuotationDiscounts($quotation->lb_record_primary_key);
         foreach ($quotation_discount_arr->data as $discount_item) {
             $quo_discount_new = new LbQuotationDiscount();
             $quo_discount_new->lb_quotation_id = $quo_new->lb_record_primary_key;
             $quo_discount_new->lb_quotation_discount_description = $discount_item->lb_quotation_discount_description;
             $quo_discount_new->lb_quotation_discount_total = $discount_item->lb_quotation_discount_total;
             $quo_discount_new->lb_quotation_discount_value = $discount_item->lb_quotation_discount_value;
             $quo_discount_new->save();
         }
         //END
         //Add Thong tin total
         $quotation_total = LbQuotationTotal::model()->getQuotationTotal($quotation->lb_record_primary_key);
         $quo_total_new = new LbQuotationTotal();
         $quo_total_new->lb_quotation_id = $quo_new->lb_record_primary_key;
         $quo_total_new->lb_quotation_subtotal = $quotation_total->lb_quotation_subtotal;
         $quo_total_new->lb_quotation_total_after_discount = $quotation_total->lb_quotation_total_after_discount;
         $quo_total_new->lb_quotation_total_after_tax = $quotation_total->lb_quotation_total_after_tax;
         $quo_total_new->lb_quotation_total_after_total = $quotation_total->lb_quotation_total_after_total;
         $quo_total_new->save();
         //Add thong tin item
         $quotation_item_arr = LbQuotationItem::model()->getquotationItems($quo_new->lb_record_primary_key);
         foreach ($quotation_item_arr->data as $item) {
             $quo_item_new = new LbQuotationItem();
             $quo_item_new->lb_quotation_id = $quo_new->lb_record_primary_key;
             $quo_item_new->lb_quotation_item_price = $item->lb_quotation_item_price;
             $quo_item_new->lb_quotation_item_description = $item->lb_quotation_item_description;
             $quo_item_new->lb_quotation_item_quantity = $item->lb_quotation_item_quantity;
             $quo_item_new->lb_quotation_item_total = $item->lb_quotation_item_total;
             $quo_item_new->save();
         }
         //END
     }
 }