示例#1
0
 public function docsTest()
 {
     $types = Doctype::find()->All();
     foreach ($types as $type) {
         $docs = Docs::find()->where(["doctype" => $type->id])->orderBy('docnum')->All();
         $num = 0;
         foreach ($docs as $doc) {
             if ($num != 0) {
                 if ($num == $doc->docnum) {
                     $this->errors[] = 'Duplicate documenet number:' . $doc->docnum . ' id: ' . $doc->id . " type: " . $type->name;
                 }
                 if ($num + 1 != $doc->docnum) {
                     $this->errors[] = 'Invalid documenet number:' . $doc->docnum . ' id: ' . $doc->id . " type: " . $type->name;
                 }
             }
             $num = $doc->docnum;
         }
     }
 }
示例#2
0
 public function make()
 {
     $text = '';
     //$yiidatetimesec = Yii::$app->locale->getDateFormat('yiidatetimesec');
     //$phpdbdatetime = Yii::$app->locale->getDateFormat('phpdbdatetime');
     $from_date = $this->from_date;
     $to_date = $this->to_date;
     $types = array(3, 4, 9, 11, 13, 14);
     //$criteria=new CDbCriteria;
     //$criteria->condition="issue_date BETWEEN :from_date AND :to_date";
     //$criteria->params=array(
     //    ':from_date' => $from_date,
     //    ':to_date' => $to_date,
     //  );
     //$criteria->compare('doctype', $types);
     $docs = Docs::find()->where(['BETWEEN', 'issue_date', $from_date, $to_date])->andWhere(['doctype' => $types])->All();
     $vatper = 18;
     $start = array('t_wovat' => 0, 't_vat' => 0, 'ns_t_wovat' => 0, 'ns_t_vat' => 0, 'i_doc_count' => 0, 't_exclude_vat' => 0, 'ot_vat' => 0, 'at_vat' => 0, 'o_doc_count' => 0, 'sum' => 0);
     foreach ($docs as $doc) {
         $text .= $doc->pcn874() . "\n";
         if (in_array($doc->doctype, array(3, 4, 9, 11))) {
             if ($doc->sub_total != 0) {
                 if ($doc->vat / $doc->sub_total * 100 == $vatper) {
                     $start['t_wovat'] += $doc->sub_total;
                     $start['t_vat'] += $doc->vat;
                 } else {
                     if ($doc->vat == 0) {
                         $start['t_exclude_vat'] += $doc->sub_total;
                     } else {
                         $start['ns_t_wovat'] += $doc->sub_total;
                         $start['ns_t_vat'] += $doc->vat;
                     }
                 }
             }
             $start['i_doc_count']++;
         }
         if (in_array($doc->doctype, array(13, 14))) {
             if ($doc->doctype == 13) {
                 $start['ot_vat'] += $doc->vat;
             } else {
                 $start['at_vat'] += $doc->vat;
             }
             $start['o_doc_count']++;
         }
     }
     $start['sum'] = $start['t_vat'] + $start['ns_t_vat'];
     return $this->start($start) . "\n" . $text . $this->end();
 }
示例#3
0
 public function make($cid)
 {
     $this->id = rand(0, 999999);
     //$this->iniArr=array('b110'=>0,'b100'=>0,'m100'=>0,'c100'=>0,'d100'=>0,'d110'=>0,'d120'=>0,);
     //$this->docArr=array(0=>0,305=>0,300=>0,);
     $bkmv = '';
     //$this->line=1;
     //$yiidatetimesec=Yii::$app->locale->getDateFormat('yiidatetimesec');
     //$phpdbdatetime=Yii::$app->locale->getDateFormat('phpdbdatetime');
     $from_date = $this->from_date . " 00:00:00";
     $to_date = $this->to_date . " 23:59:59";
     //$types=array(3,4,9,11,13,14);
     //accounts
     $accounts = Accounts::find()->All();
     $record = array('id' => 'B110', 'name' => OpenFormatType::getDesc('B110'), 'count' => 0);
     foreach ($accounts as $account) {
         $this->line++;
         $bkmv .= $account->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //items
     $items = Item::find()->All();
     $record = array('id' => 'M100', 'name' => OpenFormatType::getDesc('M100'), 'count' => 0);
     foreach ($items as $item) {
         $this->line++;
         $bkmv .= $item->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //
     //transactions
     $transactions = Transactions::find()->where(['BETWEEN', 'valuedate', $from_date, $to_date])->All();
     $record = array('id' => 'B100', 'name' => OpenFormatType::getDesc('B100'), 'count' => 0);
     foreach ($transactions as $transaction) {
         $this->line++;
         $bkmv .= $transaction->openfrmt($this->line, $from_date, $to_date);
         $record['count']++;
     }
     $this->iniArr[] = $record;
     //docs
     $docs = Docs::find()->where(['BETWEEN', 'due_date', $from_date, $to_date])->All();
     //OpenFormatType::getDesc('C100')
     $record = array('id' => 'C100', 'name' => OpenFormatType::getDesc('C100'), 'count' => 0);
     $d110 = array('id' => 'D110', 'name' => OpenFormatType::getDesc('D110'), 'count' => 0);
     $d120 = array('id' => 'D120', 'name' => OpenFormatType::getDesc('D120'), 'count' => 0);
     foreach ($docs as $doc) {
         if ($doc->docType->openformat != '0') {
             $this->line++;
             $bkmv .= $doc->openfrmt($this->line, $from_date, $to_date);
             foreach ($doc->docDetailes as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d110['count']++;
             }
             foreach ($doc->docCheques as $detial) {
                 $this->line++;
                 $bkmv .= $detial->openfrmt($this->line, $from_date, $to_date);
                 $d120['count']++;
             }
             $type = $doc->OpenfrmtType();
             $this->docArr[$type] = isset($this->docArr[$type]) ? $this->docArr[$type] + 1 : 0;
             $this->docSumArr[$type] = isset($this->docSumArr[$type]) ? $this->docSumArr[$type] + $doc->total : $doc->total;
             $record['count']++;
         }
     }
     $this->iniArr[] = $record;
     $this->iniArr[] = $d110;
     $this->iniArr[] = $d120;
     $company = \app\models\Settings::findOne(['company.name']);
     //A100
     $bkmv = $company->a100(1, $this->id, $from_date, $to_date) . $bkmv;
     //Z900
     $bkmv = $bkmv . $company->z900($this->line + 1, $this->id, $this->line + 1);
     $bkmvFile = new Files();
     $bkmvFile->name = 'bkmvdata.txt';
     $bkmvFile->path = 'openformat/';
     //
     $bkmvFile->expire = 360;
     $bkmvFile->save();
     $bkmvFile->writeFile($bkmv);
     $this->bkmvId = $bkmvFile->id;
     //A000
     $ini = $company->a000(1, $this->id, $this->line + 1, $from_date, $to_date);
     foreach ($this->iniArr as $line) {
         $ini .= $line['id'] . sprintf("%015d", $line['count']) . "\r\n";
     }
     //Z
     $iniFile = new Files();
     $iniFile->name = 'ini.txt';
     $iniFile->path = 'openformat/';
     //
     $iniFile->expire = 360;
     $iniFile->save();
     $iniFile->writeFile($ini);
     $this->iniId = $iniFile->id;
     return $this->id;
 }