예제 #1
0
 function actionCreate()
 {
     $model = new LbQuotation();
     // get default ownCompany and ownCompany address
     $ownCompany = LbCustomer::model()->getOwnCompany();
     $ownCompanyAddress = null;
     if ($ownCompany->lb_record_primary_key) {
         $model->lb_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_company_address_id = $ownCompanyAddress->lb_record_primary_key;
         }
     }
     // save quotation Unconfirmed
     $model->saveUnconfirmed();
     // add 1 line-item by default
     $blankItem = new LbQuotationItem();
     $blankItem->addBlankItem($model->lb_record_primary_key);
     //add 1 tax by default
     $blankTax = new LbQuotationTax();
     $blankTax->addBlankTax($model->lb_record_primary_key);
     //add 1 total by default
     $blankTotal = new LbQuotationTotal();
     $blankTotal->createBlankTotal($model->lb_record_primary_key);
     $model->save();
     $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
 }
예제 #2
0
 function actionCreate()
 {
     $model = new LbQuotation();
     // get default ownCompany and ownCompany address
     $ownCompany = LbCustomer::model()->getOwnCompany();
     $ownCompanyAddress = null;
     if ($ownCompany->lb_record_primary_key) {
         $model->lb_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_company_address_id = $ownCompanyAddress->lb_record_primary_key;
         }
     }
     // save quotation Unconfirmed
     $model->saveUnconfirmed();
     // add 1 line-item by default
     $blankItem = new LbQuotationItem();
     $blankItem->addBlankItem($model->lb_record_primary_key);
     //add 1 tax by default
     $blankTax = new LbQuotationTax();
     $blankTax->addBlankTax($model->lb_record_primary_key);
     //add 1 total by default
     $blankTotal = new LbQuotationTotal();
     $blankTotal->createBlankTotal($model->lb_record_primary_key);
     $model->save();
     $id = $model->lb_record_primary_key;
     $model = $this->loadModel($id);
     $quotationItemModel = new LbQuotationItem('search');
     $quotationItemModel->unsetAttributes();
     $quotationItemModel->lb_quotation_id = $model->lb_record_primary_key;
     $quotationTaxModel = new LbQuotationTax('search');
     $quotationTaxModel->unsetAttributes();
     $quotationTaxModel->lb_quotation_id = $model->lb_record_primary_key;
     $quotationDiscountModel = new LbQuotationDiscount('search');
     $quotationDiscountModel->unsetAttributes();
     $quotationDiscountModel->lb_quotation_id = $model->lb_record_primary_key;
     $quotationTotalModel = LbQuotationTotal::model()->getQuotationTotal($id);
     LBApplication::render($this, 'view', array('model' => $model, 'quotationItemModel' => $quotationItemModel, 'quotaitonTaxModel' => $quotationTaxModel, 'quotationDiscountModel' => $quotationDiscountModel, 'quotationTotalModel' => $quotationTotalModel));
     $this->redirect(array('view', 'id' => $model->lb_record_primary_key));
 }
예제 #3
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,
             ));**/
 }