コード例 #1
0
 /**
  * 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));
 }
コード例 #2
0
ファイル: _form.php プロジェクト: nhuhtlb/linxbooks
echo CHtml::dropDownList('LbExpensesInvoice[lb_invoice_id][]', '', $option_invoice, array('multiple' => true));
//            echo Chosen::activeMultiSelect($model,'lb_expenses_amount', $option_customer, array('class'=>'span6'));
echo '</div>';
echo '</div>';
//            echo $form->dropDownListRow($invoiceModel, 'lb_invoice_id', $option_invoice, array('multiple'=>true));
echo $form->textAreaRow($model, 'lb_expenses_note', array('rows' => '3', 'cols' => '40', 'style' => 'width:210px;'));
$recurring = UserList::model()->getItemsForListCode('recurring');
$option_recurring = array('' => 'Choose Recurring') + $recurring;
echo $form->dropDownListRow($model, 'lb_expenses_recurring_id', CHtml::listData($option_recurring, 'system_list_item_id', 'system_list_item_name'));
//            foreach ($recurring_arr as $data){
//                $recurring .='<option value="'.$data->lb_record_primary_key.'">'.$data['system_list_item_name'].'</option>';
//                $option_recurring = array(''=>'Choose Recurring')+$data;
//            }
//            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>';
コード例 #3
0
ファイル: view.php プロジェクト: Lucerin/Yii-projects
//        LBApplicationUI::button('Print PDF');
echo '</div><br/>';
//$this->widget('zii.widgets.CDetailView', array(
//	'data'=>$model,
//	'attributes'=>array(
//		'lb_record_primary_key',
//		'lb_category_id',
//		'lb_expenses_amount',
//		'lb_expenses_date',
//		'lb_expenses_recurring_id',
//		'lb_expenses_brank_account_id',
//		'lb_expenses_note',
//	),
//));
//echo '<div style="float: left; width: 49%;">';
$this->widget('editable.EditableDetailView', array('id' => 'expenses-detail', 'data' => $model, 'url' => $model->getActionURL('ajaxUpdateField'), 'placement' => 'right', 'attributes' => array(array('name' => 'lb_expenses_no', 'editable' => false), array('name' => 'lb_category_id', 'editable' => array('type' => 'select', 'source' => CHtml::listData(SystemList::model()->getItemsForListCode('expenses_category'), 'system_list_item_id', 'system_list_item_name'))), array('name' => 'lb_expenses_date', 'editable' => array('type' => 'date', 'viewformat' => 'dd-mm-yyyy', 'format' => 'yyyy-mm-dd')), 'lb_expenses_amount', array('name' => 'lb_expenses_note', 'editable' => array('type' => 'textarea')), array('name' => 'lb_expenses_recurring_id', 'editable' => array('type' => 'select', 'source' => array('' => 'Choose Recurring') + CHtml::listData(UserList::model()->getItemsForListCode('recurring'), 'system_list_item_code', 'system_list_item_name'))), array('name' => 'lb_expenses_bank_account_id', 'editable' => array('type' => 'select', 'source' => array('' => 'Choose bank account') + CHtml::listData(LbBankAccount::model()->getBankAccount(Yii::app()->user->id), 'lb_record_primary_key', 'lb_bank_account'))))));
$customers = LbExpensesCustomer::model()->getCustomerExpenses($model->lb_record_primary_key);
$customer_view = '';
if (count($customers) > 0) {
    foreach ($customers as $cus) {
        $client = LbCustomer::model()->findByPk($cus->lb_customer_id);
        $customer_view .= $client['lb_customer_name'] . '; ';
    }
}
$invoices = LbExpensesInvoice::model()->getExpensesInvoice($model->lb_record_primary_key);
$invoice_view = '';
if (count($invoices) > 0) {
    foreach ($invoices as $inv) {
        $invoice = LbInvoice::model()->findByPk($inv->lb_invoice_id);
        $invoice_view .= $invoice['lb_invoice_no'] . '; ';
    }