Skip to content

Commit

Permalink
Merge pull request #709 from leon-mbs/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
leon-mbs authored Mar 4, 2024
2 parents 4152a68 + 4cde77b commit 1944b8a
Show file tree
Hide file tree
Showing 50 changed files with 706 additions and 257 deletions.
1 change: 1 addition & 0 deletions www/app/api/jsonrpc.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function Execute() {


if ($response != null) {
header("Content-type: application/json");
echo json_encode($response, JSON_UNESCAPED_UNICODE);
} else {
http_response_code(200);
Expand Down
2 changes: 2 additions & 0 deletions www/app/entity/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function afterLoad() {
$this->image_id = (int)$xml->image_id[0];
$this->noshop = (int)$xml->noshop[0];
$this->nofastfood = (int)$xml->nofastfood[0];
$this->noprice = (int)$xml->noprice[0];
$this->order = (int)$xml->order[0];
$this->discount = doubleval($xml->discount[0]);
$this->todate = intval($xml->todate[0]);
Expand All @@ -56,6 +57,7 @@ protected function beforeSave() {
$this->detail .= "<noshop>{$this->noshop}</noshop>";
$this->detail .= "<order>{$this->order}</order>";
$this->detail .= "<nofastfood>{$this->nofastfood}</nofastfood>";
$this->detail .= "<noprice>{$this->noprice}</noprice>";
if ($this->discount > 0) {
$this->detail .= "<discount>{$this->discount}</discount>";
}
Expand Down
27 changes: 26 additions & 1 deletion www/app/entity/doc/calcsalary.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ class CalcSalary extends Document
public function Execute() {
$opt = System::getOptions("salary");

$code = "_c" . $opt['coderesult'];
$code = "_c" . $opt['coderesult'];
$bonus = "_c" . $opt['codebonus'];
$fine = "_c" . $opt['codefine'];


foreach ($this->unpackDetails('detaildata') as $emp) {
Expand All @@ -29,6 +31,29 @@ public function Execute() {
$eacc->optype = EmpAcc::SALARY;
$eacc->amount = $am;
$eacc->save();

$am = $emp->{$bonus};
if($am > 0) {
$eacc = new EmpAcc();
$eacc->emp_id = $emp->employee_id;
$eacc->document_id = $this->document_id;
$eacc->optype = EmpAcc::BONUS;
$eacc->amount = 0-$am;
$eacc->save();

}

$am = $emp->{$fine};
if($am > 0) {
$eacc = new EmpAcc();
$eacc->emp_id = $emp->employee_id;
$eacc->document_id = $this->document_id;
$eacc->optype = EmpAcc::FINE;
$eacc->amount = $am;
$eacc->save();

}

}

return true;
Expand Down
108 changes: 49 additions & 59 deletions www/app/entity/doc/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ class Document extends \ZCL\DB\Entity
*/
public $headerdata = array();

/**
* Массив ассоциативных массивов (строк) содержащих строки детальной части (таблицы) документа
*
* @var mixed
*/
public $detaildata = array();

private static $_metalist = array();

/**
Expand Down Expand Up @@ -139,13 +135,7 @@ protected function beforeSave() {
$this->packData();


/*
$prev = Document::getFirst(" document_id <> {$this->document_id} and user_id = {$this->user_id} and meta_id={$this->meta_id}", "document_id desc");
$diff = time() - $prev->lastupdate ;
if($diff <= 10 && $prev != false && $this->amount==$prev->amount) {
// throw new \Exception("Дублювання документа");
}
*/


}

Expand Down Expand Up @@ -175,6 +165,11 @@ private function packData() {
$this->content .= "</header>";

$this->content .= "</doc>";

$this->content .= serialize($this->detaildata);



}

/**
Expand All @@ -188,27 +183,61 @@ private function unpackData() {
return;
}

$xml = @simplexml_load_string($this->content) ;
$endxml = strpos($this->content,'</header></doc>') ;

$xml=substr($this->content,0,$endxml+15) ;

$xml = @simplexml_load_string($xml) ;
if($xml==false) {

$logger->error("Документ " . $this->document_id . " Невірний контент");
// $logger->error( $this->content );
return;
}


foreach ($xml->header->children() as $child) {
$ch = (string)$child;
/* if(is_numeric($ch)) {
if(ctype_digit($ch)) $ch = intval($ch);
else $ch = doubleval($ch) ;
}
*/

$this->headerdata[(string)$child->getName()] = $ch;
}


$det = $xml=substr($this->content,$endxml+15) ;
$this->detaildata = @unserialize($det) ;
if(!is_array($this->detaildata)) {
$this->detaildata =[];
}

}


/**
* распаковываем данные детализации
*
*/
public function unpackDetails($dataname) {

if(is_array($this->detaildata[$dataname] ?? null)) {
return $this->detaildata[$dataname] ;
}

//для совместимтсти
$list = @unserialize(@base64_decode($this->headerdata[$dataname] ??''));
if (is_array($list)) {
return $list;
} else {
return array();
}
}

public function packDetails($dataname, $list) {
// $data = base64_encode(serialize($list));
// $this->headerdata[$dataname] = $data;
$this->detaildata[$dataname]= $list;

}


/**
* Генерация HTML для печатной формы
*
Expand Down Expand Up @@ -849,46 +878,7 @@ public function getRelationBased() {
return $list;
}

/**
* распаковываем данные детализации
*
*/
public function unpackDetails($dataname) {
$list = @unserialize(@base64_decode($this->headerdata[$dataname] ??''));
if (is_array($list)) {
return $list;
} else {
return array();
}
}

public function packDetails($dataname, $list) {
$data = base64_encode(serialize($list));
$this->headerdata[$dataname] = $data;
//для поиска по контексту
$s = array();
foreach ($list as $it) {
if (strlen($it->itemname ?? '') > 0) {
$s[] = $it->itemname;
}
if (strlen($it->item_code ?? '') > 0) {
$s[] = $it->item_code;
}
if (strlen($it->bar_code ?? '') > 0) {
$s[] = $it->bar_code;
}
if (strlen($it->service_name ?? '') > 0) {
$s[] = $it->service_name;
}

if (strlen($it->snumber ?? '') > 0) {
$s[] = $it->snumber;
}

}
$this->headerdata["__searchdata__"] = serialize($s);
}


/**
* Локализованное название документа по мета имени
*
Expand Down
6 changes: 6 additions & 0 deletions www/app/entity/doc/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ protected function onState($state, $oldstate) {

$this->unreserve() ;

}
if ( $state == self::STATE_READYTOSHIP) {

$this->unreserve() ;
$this->reserve() ;

}
if ($state == self::STATE_INPROCESS) {

Expand Down
37 changes: 34 additions & 3 deletions www/app/entity/doc/orderfood.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,26 @@ public function generatePosReport($ps=false,$bill=false) {
$i= rand(0, count($frases) -1) ;
$header['checkslogan'] = $frases[$i];
}

if(strlen($header['checkslogan'] ??'') ==0) {
$header['checkslogan'] = false;
}
//промокод
$pc = \App\Entity\PromoCode::find('type=2 and disabled <> 1','id desc') ;
foreach($pc as $p) {

if($p->dateto >0 && $p->dateto < time() ) {
continue;
}
if($p->showcheck==1) {
$header['promo'] = 'Промокод '. $p->code . " на {$p->disc}% знижку";
breack;
}
}


if(strlen($header['promo'] ??'') ==0) {
$header['promo'] = false;
}

if($ps) {
$report = new \App\Report('doc/orderfood_bill_ps.tpl');
Expand Down Expand Up @@ -178,6 +197,7 @@ public function DoPayment() {
$conn = \ZDB\DB::getConnect();
$conn->Execute("delete from paylist where document_id =" . $this->document_id);
$conn->Execute("delete from iostate where iotype = 50 AND document_id=" . $this->document_id);
$conn->Execute("delete from empacc where document_id=" . $this->document_id);


if ($this->headerdata['payment'] > 0 && $this->payed > 0) {
Expand All @@ -197,8 +217,19 @@ public function DoPayment() {
}

\App\Entity\IOState::addIOState($this->document_id, $this->payed, \App\Entity\IOState::TYPE_BASE_OUTCOME);


//бонус сотруднику

$disc = \App\System::getOptions("discount");
$emp_id = \App\System::getUser()->employee_id ;
if($emp_id >0 && $disc["bonussell"] >0) {
$b = $this->amount * $disc["bonussell"] / 100;
$ua = new \App\Entity\EmpAcc();
$ua->optype = \App\Entity\EmpAcc::BONUS;
$ua->document_id = $this->document_id;
$ua->emp_id = $emp_id;
$ua->amount = $b;
$ua->save();
}
}
}

Expand Down
37 changes: 37 additions & 0 deletions www/app/entity/doc/poscheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,29 @@ public function generatePosReport($ps=false) {
$i= rand(0, count($frases) -1) ;
$header['checkslogan'] = $frases[$i];
}
if(strlen($header['checkslogan'] ??'') ==0) {
$header['checkslogan'] = false;
}

//промокод
$pc = \App\Entity\PromoCode::find('type=2 and disabled <> 1','id desc') ;
foreach($pc as $p) {

if($p->dateto >0 && $p->dateto < time() ) {
continue;
}
if($p->showcheck==1) {
$header['promo'] = 'Промокод '. $p->code . " на {$p->disc}% знижку";
breack;
}
}


if(strlen($header['promo'] ??'') ==0) {
$header['promo'] = false;
}


$header['form1'] = false;
$header['form2'] = false;
$header['form3'] = false;
Expand Down Expand Up @@ -346,6 +368,21 @@ public function Execute() {
\App\Entity\PromoCode::apply($this->headerdata['promocode'],$this);
};

//бонус сотруднику

$disc = \App\System::getOptions("discount");
$emp_id = \App\System::getUser()->employee_id ;
if($emp_id >0 && $disc["bonussell"] >0) {
$b = $this->amount * $disc["bonussell"] / 100;
$ua = new \App\Entity\EmpAcc();
$ua->optype = \App\Entity\EmpAcc::BONUS;
$ua->document_id = $this->document_id;
$ua->emp_id = $emp_id;
$ua->amount = $b;
$ua->save();

}


return true;
}
Expand Down
19 changes: 19 additions & 0 deletions www/app/entity/doc/returnissue.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,25 @@ public function Execute() {
$pay->save();
}

//штраф сотруднику
if ($this->parent_id > 0) {
$parent = Document::load($this->parent_id);
$user = \App\Entity\User::load($parent->user_id);
$disc = \App\System::getOptions("discount");
$emp_id = \App\System::getUser()->employee_id ;
if($emp_id >0 && $disc["fineret"] >0 && $parent->meta_name=='POSCheck') {
$b = $this->amount * $disc["fineret"] / 100;
$ua = new \App\Entity\EmpAcc();
$ua->optype = \App\Entity\EmpAcc::FINE;
$ua->document_id = $this->document_id;
$ua->emp_id = $emp_id;
$ua->amount = 0-$b;
$ua->save();

}

}

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions www/app/entity/doc/serviceact.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function generateReport() {
"amount" => H::fa($ser->price * $ser->quantity)
);
}
$totalstr = \App\Util::money2str_ua($this->payamount);

$header = array('date' => H::fd($this->document_date),
"_detail" => $detail,
Expand All @@ -47,6 +48,7 @@ public function generateReport() {
"isfirm" => strlen($firm["firm_name"]) > 0,
"iscontract" => $this->headerdata["contract_id"] > 0,
"totaldisc" => $this->headerdata["totaldisc"] > 0 ? H::fa($this->headerdata["totaldisc"]) : false,
"totalstr" => $totalstr,
"bonus" => $this->headerdata["bonus"] > 0 ? H::fa($this->headerdata["bonus"]) : false,
"devsn" => $this->headerdata["devsn"],
"devdesc" => $this->headerdata["devdesc"],
Expand Down
3 changes: 2 additions & 1 deletion www/app/entity/doc/ttn.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,9 @@ public function Execute() {
public function onState($state, $oldstate) {

if ($state == Document::STATE_INSHIPMENT) {

//расходы на доставку
if ($this->headerdata['ship_amount'] > 0) {
if ($this->headerdata['ship_amount'] > 0 && $this->headerdata['payseller'] == 1) {
$payed = \App\Entity\Pay::addPayment($this->document_id, $this->document_date, 0 - $this->headerdata['ship_amount'], H::getDefMF());
if ($payed > 0) {
$this->payed = $payed;
Expand Down
Loading

0 comments on commit 1944b8a

Please sign in to comment.