public function addSingleLine($account_id, $sum, $valuedate = null) { $round = new Transactions(); $round->num = $this->num; $round->account_id = $account_id; $round->type = $this->type; $round->refnum1 = $this->refnum1; $round->refnum2 = $this->refnum2; $round->valuedate = $this->valuedate; if ($valuedate != null) { $round->valuedate = $valuedate; } $round->details = $this->details; $round->currency_id = $this->currency_id; $round->sum = $sum; $round->owner_id = $this->owner_id; $round->linenum = $this->linenum; $this->linenum++; $this->num = $round->save(); return $this; }
/** * Creates a new Transactions model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Transactions(); // ambil data post variable $post = Yii::$app->request->post(); // coba load ke model Transactions dan TransactionDetails if ($model->load($post) && $this->loadDetails($post)) { // save master record if ($model->save()) { foreach ($this->details as $detail) { // set foreign key $detail->trans_id = $model->id; // save detail record $detail->save(); } } else { return $this->render('create', ['model' => $model, 'post' => $this->details]); } // redirect return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model, 'post' => $this->details]); } }
public function pay() { $this->dates(); $date = $this->to_date; /* $tnum = Transaction(0, TRAN_PRETAX, IRS, $ref1, $ref2, $date, $details, $this->tax_sum); $tnum = Transaction($tnum, TRAN_PRETAX, PRETAX, $ref1, $ref2, $date, $details, $this->tax_sum * -1.0); $tnum = Transaction($tnum, TRAN_PRETAX, IRS, $ref1, $ref2, $date, $details, $this->custtax_total); $tnum = Transaction($tnum, TRAN_PRETAX, CUSTTAX, $ref1, $ref2, $date, $details, $this->custtax_total * -1.0); */ $irs = \app\helpers\Linet3Helper::getSetting('company.acc.irs'); $pretax = \app\helpers\Linet3Helper::getSetting('company.acc.pretax'); $custtax = \app\helpers\Linet3Helper::getSetting('company.acc.custtax'); $cur = \app\helpers\Linet3Helper::getSetting('company.cur'); $owner = Yii::$app->user->id; $line = 1; $accout = new Transactions(); $accout->account_id = $irs; //IRS $accout->type = 14; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->tax_sum; $line++; $num = $accout->save(); $accout = new Transactions(); $accout->account_id = $pretax; //PRETAX $accout->type = 14; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->tax_sum * -1; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $irs; //IRS $accout->type = 14; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->custtax_total; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $custtax; //CUSTTAX $accout->type = 14; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'tax') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->custtax_total * -1.0; $line++; $accout->save(); }
public function actionBuyItems() { /* @var $product Products */ Yii::$app->response->format = 'json'; $return_data = ['status' => 'error', 'data' => []]; $basket = Yii::$app->request->post('data'); $items = []; if (isset($basket['items'])) { $items = $basket['items']; } $amount_paid = 0; if (isset($basket['amount_paid'])) { $amount_paid = $basket['amount_paid']; } $total_amount = 0; if (isset($basket['total_amount'])) { $total_amount = $basket['total_amount']; } if (!empty($items)) { $transaction = new Transactions(); $transaction->total_quantity = 0; $transaction->amount_paid = $amount_paid; $transaction->user_id = Yii::$app->user->id; $transaction->reason_id = Transactions::SELL; $transaction->total_amount = $total_amount; if ($transaction->save()) { $total_quantity = 0; foreach ($items as $item) { $transaction_item = new TransactionItems(); $transaction_item->product_id = $item['id']; $transaction_item->transaction_id = $transaction->id; $transaction_item->quantity = $item['quantity']; $total_quantity += intval($transaction_item->quantity); $transaction_item->buy_price = $item['buy_price']; $transaction_item->sell_price = $item['sell_price']; $transaction_item->name = $item['name']; if ($transaction_item->save()) { $product = Products::findOne($transaction_item->product_id); $product->quantity = $product->quantity - $transaction_item->quantity; $product->save(); } } $transaction->total_quantity = $total_quantity; $transaction->save(); Yii::$app->getSession()->setFlash('success', 'Transaction was successfully saved.'); $return_data = ['status' => 'success', 'data' => ['bill_num' => str_pad($transaction->id, 8, 0, STR_PAD_LEFT)]]; } else { $return_data = ['status' => 'error', 'data' => ['Error in Transaction']]; } } return $return_data; }
public function pay() { $this->dates(); $this->payvat_acc = \app\helpers\Linet3Helper::getSetting('company.acc.payvat'); $date = $this->to_date; $cur = \app\helpers\Linet3Helper::getSetting('company.cur'); $owner = Yii::$app->user->id; $line = 1; $accout = new Transactions(); $accout->account_id = $this->selvat_acc; $accout->type = 6; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->selvat_total * -1.0; $line++; $num = $accout->save(); $accout = new Transactions(); $accout->account_id = $this->payvat_acc; $accout->type = 6; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->selvat_total; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $this->buyvat_acc; $accout->type = 6; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->buyvat_total; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $this->payvat_acc; $accout->type = 6; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->buyvat_total * -1.0; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $this->assetvat_acc; $accout->type = 6; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->assetvat_total; $line++; $accout->save(); $accout = new Transactions(); $accout->account_id = $this->payvat_acc; $accout->type = 6; $accout->num = $num; //$accout->refnum1 = $this->from_date; //$accout->refnum2 = $this->to_date; $accout->valuedate = $date; $accout->details = Yii::t('app', 'vat') . " " . $this->from_month . "-" . $this->to_month . "/" . $this->year; $accout->currency_id = $cur; $accout->owner_id = $owner; $accout->linenum = $line; $accout->sum = $this->assetvat_total * -1.0; $line++; $accout->save(); //$s = $this->selvat_total * -1.0; //$tnum = Transaction(0, VAT, SELLVAT, $ref1, $ref2, $date, _('VAT'), $s); //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $sellvat); //$b = $this->buyvat_total * -1.0; //$tnum = Transaction(0, VAT, BUYVAT, $ref1, $ref2, $date, _('VAT'), $buyvat); //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $b); //$a = $this->assetvat_total * -1.0; //$tnum = Transaction(0, VAT, ASSETVAT, $ref1, $ref2, $date, _('VAT'), $assetvat); //$tnum = Transaction($tnum, VAT, PAYVAT, $ref1, $ref2, $date, _('VAT'), $a); }
public function readBkmv() { //sort $this->sortBkmvFile(); //skip for testing // //new company //get perm from ini //if (substr($line,395,1)=='2') // $encoding="ibm862"; //else $encoding = "windows-1255"; //$encoding="ibm862"; Yii::info('start Openimport'); //$bkmv = $yiiBasepath."/files/".$configPath."/openformt/bkmvdata.txt-sorted"; $bkmv = $this->bkmvFile . "-sorted"; $suc = array(); $suc['B110'] = 0; $suc['A100'] = 0; $suc['B100'] = 0; $suc['C100'] = 0; $suc['M100'] = 0; $suc['D110'] = 0; $suc['D120'] = 0; $suc['Z900'] = 0; $analze = array(); $analze['B110'] = 0; $analze['A100'] = 0; $analze['B100'] = 0; $analze['C100'] = 0; $analze['M100'] = 0; $analze['D110'] = 0; $analze['D120'] = 0; $analze['Z900'] = 0; $accType = 200; //DELETE FROM `qwe_docCheques` WHERE 1;DELETE FROM `qwe_docDetails` WHERE 1;DELETE FROM `qwe_accounts` WHERE 1;DELETE FROM `qwe_items` WHERE 1;DELETE FROM `qwe_docs` WHERE 1; if ($fp = fopen($bkmv, 'r')) { while ($line = fgets($fp)) { @($line = iconv($encoding, "UTF-8//IGNORE", $line)); //$line=utf8_encode($line); $type = substr($line, 0, 4); //$obj=$this->readline($line,$type); $obj = true; if (!$obj) { //$suc[$type]--; } else { //foreach ($obj as &$value) // if ($encoding=="ibm862") // $value = iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $value))); if ($type == 'B110') { //Acc Haeder /* Account Import */ $acc = new Accounts(); $acc->readLine($line, $type); if (isset($this->accTypeIndex[$acc->type])) { $this->accDesc[$acc->type] = $this->accDesc[$acc->type] . "," . $acc->name; } else { $this->accDesc[$acc->type] = $acc->name; $this->accTypeIndex[$acc->type] = $accType; $accType++; } $acc->type = $this->accTypeIndex[$acc->type]; if ($acc->currency_id == '') { $acc->currency_id = 'ILS'; } $acc->system_acc = 0; if (!$acc->save()) { var_dump($acc->errors); } //get new acc index save old unset($acc); //*/ } if ($type == 'M100') { //Item In Stock $item = new Item(); $item->category_id = 0; $item->parent_item_id = 0; $item->isProduct = 0; $item->profit = 0; $item->stockType = 0; $item->readLine($line, $type); if ($item->currency_id == '') { $item->currency_id = 'ILS'; } if ($item->sku == '') { $item->sku = $item->id; } if ($item->itemVatCat_id == '') { $item->itemVatCat_id = '1'; } if ($item->unit_id == '') { $item->unit_id = '1'; } if (!$item->save()) { var_dump($item->errors); } unset($item); //*/ } if ($type == 'C100') { //Doc Haeder //return "done!"; //Yii::$app->end(); //find type //global $DocOpenType; $doc = new Docs(); $doc->readLine($line, $type); $doc->action = true; $doc->status = true; //needtoChange //Yii::log($doc,'info','app'); if ($doc->currency_id == '') { $doc->currency_id = 'ILS'; } if (!$doc->save()) { var_dump($doc->errors); } unset($doc); /* if ((isset($DocOpenType[$obj['doctype']])) && (isset($accIndex[$obj['account']]))){ $obj['doctype']=$DocOpenType[$obj['doctype']]; $doc=new document($obj['doctype']); $stype=$obj['doctype']; foreach($obj as $key=>$value){ $doc->$key=$value;//print "$key <br />"; } $doc->account=$accIndex[$doc->account]; //search for old acc index if (isset($doc->rcptdetials)) unset($doc->rcptdetials); if (isset($doc->docdetials)) unset($doc->docdetials); if($check){ if((strtotime($doc->issue_date)>$begindmy)&&(strtotime($doc->issue_date)<$enddmy)) $docIndex[$stype.$obj["docnum"]]=$doc->newDocument(); //print "we are chking!"; }else{ $docIndex[$stype.$obj["docnum"]]=$doc->newDocument(); } //get new doc index save old unset($doc); } */ } if ($type == 'D110') { //Doc Detial $docdetial = new Docdetails(); $docdetial->readLine($line, $type); if ($docdetial->unit_id == '') { $docdetial->unit_id = 1; } if ($docdetial->currency_id == '') { $docdetial->currency_id = 'ILS'; } //Yii::log($docdetial,'info','app'); if (!$docdetial->save()) { var_dump($docdetial->errors); } unset($docdetial); /* global $DocOpenType; $stype=$DocOpenType[$obj['doctype']]; if (isset($docIndex[$stype.$obj["num"]])){ $docdetial=new documentDetail; $docdetial->price=$obj['price']; unset($obj['doctype']); unset($obj['price']); foreach($obj as $key=>$value){ $docdetial->{$key}=$value;//print "$key <br />"; } $docdetial->num=$docIndex[$stype.$obj["num"]]; $docdetial->newDetial(); //search for old doc index //die; //update to new index unset($docdetial); }// */ } if ($type == 'D120') { //Kaballa Detial $rcptdetial = new Doccheques(); $rcptdetial->readLine($line, $type); //Yii::log($rcptdetial, 'info', 'app'); if ($rcptdetial->currency_id == '') { $rcptdetial->currency_id = 'ILS'; } if (!$rcptdetial->save()) { var_dump($rcptdetial->errors); } unset($rcptdetial); /* global $DocOpenType; $stype=$DocOpenType[$obj['doctype']]; if (isset($docIndex[$stype.$obj["refnum"]])){ $rcptdetial=new receiptDetail(); //$stype=$DocOpenType[$obj['doctype']]; $rcptdetial->sum=(float)$obj['sum']; unset($obj['sum']); unset($obj['doctype']); foreach($obj as $key=>$value){ $rcptdetial->$key=$value; } $rcptdetial->refnum=$docIndex[$stype.$obj["refnum"]]; $rcptdetial->newDetial(); //search for old doc index //update to new index unset($rcptdetial); } */ } if ($type == 'B100') { //Move Recored $transaction = new Transactions(); $transaction->readLine($line, $type); if ($transaction->type == '') { $transaction->type = 1; } if ($transaction->currency_id == '') { $transaction->currency_id = 'ILS'; } if (!$transaction->save()) { var_dump($transaction->errors); } //Yii::log($transaction,'info','app'); unset($transaction); /* //print $obj['value'].":".$obj['type']; global $openTransType; if (isset($accIndex[$obj['account']])){ $bsum= $obj['sum']; if($obj['value']==1) $bsum= -1 * $obj['sum']; //print $bsum."<br />\n"; $usum=$bsum*-1; $uaccount=$obj['account1']; $stype=$openTransType[$obj['type']]; unset($obj['sum']); unset($obj['value']); unset($obj['account1']); //adam:! need to reset type of action! $transaction=new transaction; foreach($obj as $key=>$value){ $transaction->$key=$value;//print "$key <br />"; } $transaction->type=$stype; $transaction->sum=$bsum; $transaction->account=$accIndex[$obj['account']]; if($check){ if((strtotime($transaction->date)>$begindmy)&&(strtotime($transaction->date)<$enddmy)){ // "gone"; $transaction->newTransactions(); } //print "gone2"; }else{ //print "gone1"; $transaction->newTransactions(); } unset($transaction); }// */ } unset($obj); $suc[$type]++; } $analze[$type]++; //if ($analze[$type]>100) break; } Yii::info("End OpenImport"); //print_r($docIndex); //end loop //print_r($accIndex); } else { echo Yii::t('app', "error cant open file!"); } }