Skip to content

Commit

Permalink
Merge pull request #751 from leon-mbs/dev
Browse files Browse the repository at this point in the history
hotfix
  • Loading branch information
leon-mbs authored Apr 21, 2024
2 parents 879cfee + b60b588 commit e55a055
Show file tree
Hide file tree
Showing 33 changed files with 206 additions and 239 deletions.
8 changes: 1 addition & 7 deletions www/app/api/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,7 @@ public function save($args) {

$item->thumb = "data:{$image->mime};base64," . base64_encode($thumb->getImageAsString());
}
$conn = \ZDB\DB::getConnect();
if($conn->dataProvider=='postgres') {
$image->thumb = pg_escape_bytea($image->thumb);
$image->content = pg_escape_bytea($image->content);

}


$image->save();
$item->image_id = $image->image_id;

Expand Down
7 changes: 7 additions & 0 deletions www/app/entity/customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ protected function beforeSave() {
$this->detail .= "<comment><![CDATA[{$this->comment}]]></comment>";
$this->detail .= "</detail>";



return true;
}

Expand Down Expand Up @@ -100,6 +102,11 @@ protected function afterLoad() {
parent::afterLoad();
}

public function afterSave($update) {
if($update==false) {
\App\Entity\Subscribe::onNewCustomer($this->customer_id) ;
}
}
public function beforeDelete() {

$conn = \ZDB\DB::getConnect();
Expand Down
3 changes: 0 additions & 3 deletions www/app/entity/doc/document.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,9 +645,6 @@ public function nextNumber($branch_id = 0) {
$branch = " and branch_id=" . $branch_id;
}
$limit =" limit 0,1";
if($conn->dataProvider=="postgres") {
$limit =" limit 1";
}
$sql = "select document_number from documents where meta_id='{$this->meta_id}' {$branch} order by document_id desc ".$limit;
$prevnumber = $conn->GetOne($sql);
if (strlen($prevnumber) == 0) {
Expand Down
4 changes: 1 addition & 3 deletions www/app/entity/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,7 @@ public function getNearestSerie($store_id = 0) {
}

$limit =" limit 0,1";
if($conn->dataProvider=="postgres") {
$limit =" limit 1";
}

$sql .= " order by sdate desc ". $limit;


Expand Down
4 changes: 1 addition & 3 deletions www/app/entity/stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ public static function pickup($store_id, $item) {
if ($last == null) {
$conn = \ZDB\DB::getConnect();
$limit =" limit 0,1";
if($conn->dataProvider=="postgres") {
$limit =" limit 1";
}

$lastpartion = $conn->GetOne("select coalesce(partion,0) from store_stock where qty > 0 and item_id={$item->item_id} order by stock_id desc ".$limit);
if ($lastpartion == 0) {
$lastpartion = $item->price/2; //типа учетная цена
Expand Down
195 changes: 130 additions & 65 deletions www/app/entity/subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function beforeSave() {
public static function getEventList() {
$list = array();
$list[self::EVENT_DOCSTATE] = "Зміна статусу документа";
// $list[self::EVENT_NEWCUST] = "Новий контрвгент";
$list[self::EVENT_NEWCUST] = "Новий контрвгент";

return $list;
}
Expand All @@ -105,14 +105,12 @@ public static function getMsgTypeList($rt=0) {
if($sms['smstype']==2) {
$list[self::MSG_VIBER] = "Viber";
}

if(strlen(\App\System::getOption("common", 'tbtoken'))>0) {
$list[self::MSG_BOT] = "Телеграм бот";

}


if($rt==self::RSV_CUSTOMER) {
unset($list[self::MSG_BOT]) ;
unset($list[self::MSG_NOTIFY]) ;
}

Expand Down Expand Up @@ -156,85 +154,141 @@ public static function onDocumentState($doc_id, $state) {
continue;
}



$ret = '';
$phone = '';
$viber = '';
$chat_id = '';
// $viber='';
$email = '';
$notify = 0;
$options=[];
$c=null;
$u=null;


if ($sub->reciever_type == self::RSV_CUSTOMER) {
$c = \App\Entity\Customer::load($doc->customer_id);
if ($c != null && $c->nosubs != 1) {
$phone = $c->phone;
$viber = $c->viber;
$email = $c->email;
$chat_id = $c->chat_id;
if($c->nosubs != 1) {
$c = \App\Entity\Customer::load($doc->customer_id);
}
}
if ($sub->reciever_type == self::RSV_DOCAUTHOR) {
$u = \App\Entity\User::load($doc->user_id);
if ($u != null) {
$phone = $u->phone;
$viber = $u->viber;
$email = $u->email;
$chat_id = $u->chat_id;
$notify = $doc->user_id;
}
$u = \App\Entity\User::load($doc->headerdata['author']);
}
if ($sub->reciever_type == self::RSV_USER) {
$u = \App\Entity\User::load($sub->user_id);
if ($u != null) {
$phone = $u->phone;
$viber = $u->viber;
$email = $u->email;
$chat_id = $u->chat_id;
$notify = $sub->user_id;
}
}


if ($c != null ) {
$options['phone'] = $c->phone;
$options['viber'] = $c->viber;
$options['email'] = $c->email;
$options['chat_id'] = $c->chat_id;
}

if ($u != null) {
$options['phone'] = $u->phone;
$options['viber'] = $u->viber;
$options['email'] = $u->email;
$options['chat_id'] = $u->chat_id;
$options['notifyuser'] = $doc->user_id;
}
$options['doc'] = $doc;

$text = $sub->getTextDoc($doc);
if ($notify > 0 && $sub->msg_type == self::MSG_NOTIFY) {
self::sendNotify($notify, $text);


$text = $sub->sendmsg($text,$options);




}
}

//Новый контрагент
public static function onNewCustomer($customer_id) {
$c = \App\Entity\Customer::load($customer_id);

$list = self::find('disabled <> 1 and sub_type= ' . self::EVENT_NEWCUST);
foreach ($list as $sub) {
$options=[];

$u=null;


if ($sub->reciever_type == self::RSV_CUSTOMER) {
if($c->nosubs == 1) {
continue;
}
}
if ( $sub->reciever_type== self::RSV_SYSTEM) {
if ($sub->reciever_type == self::RSV_USER) {
$u = \App\Entity\User::load($sub->user_id);
}


if ($c != null ) {
$options['phone'] = $c->phone;
$options['viber'] = $c->viber;
$options['email'] = $c->email;
$options['chat_id'] = $c->chat_id;
}

if ($u != null) {
$options['phone'] = $u->phone;
$options['viber'] = $u->viber;
$options['email'] = $u->email;
$options['chat_id'] = $u->chat_id;
$options['notifyuser'] = $u->user_id;
}
// $options['c'] = $c;

$text = $sub->getTextCust($c);


$sub->sendmsg($text,$options);




}
}


private function sendmsg($text, $options=[]){
if ($options['notifyuser'] > 0 && $this->msg_type == self::MSG_NOTIFY) {
self::sendNotify($options['notifyuser'], $text);
}
if ( $this->reciever_type== self::RSV_SYSTEM) {
self::sendNotify(\App\Entity\Notify::SYSTEM, $text);
}

if (strlen($phone) > 0 && $sub->msg_type == self::MSG_SMS) {
$ret = self::sendSMS($phone, $text);
if (strlen($options['phone']) > 0 && $this->msg_type == self::MSG_SMS) {
$ret = self::sendSMS($options['phone'], $text);
}
if (strlen($email) > 0 && $sub->msg_type == self::MSG_EMAIL) {
if (strlen($options['email']) > 0 && $this->msg_type == self::MSG_EMAIL) {

if(System::useCron()) {
$task = new \App\Entity\CronTask();
$task->tasktype=\App\Entity\CronTask::TYPE_SUBSEMAIL;
$task->taskdata= serialize(array(
'email'=>$email ,
'subject'=>$sub->msgsubject ,
'email'=>$options['email'] ,
'subject'=>$this->msgsubject ,
'text'=>$text ,
'document_id'=> $sub->attach==1 ? $doc->document_id : 0
'document_id'=> $this->attach==1 ? $options['doc']->document_id : 0
));

$task->save();
} else {
$ret = self::sendEmail($email, $text, $sub->msgsubject, $sub->attach==1 ? $doc : null);
$ret = self::sendEmail($options['email'], $text, $this->msgsubject, $this->attach==1 ? $options['doc'] : null);
}

}

if(strlen($viber)==0) {
$viber = $phone;
if(strlen($options['viber'])==0) {
$options['viber'] = $options['phone'];
}
if(strlen($viber)>0 && $sub->msg_type == self::MSG_VIBER) {
$ret = self::sendViber($viber, $text) ;
if(strlen($options['viber'])>0 && $this->msg_type == self::MSG_VIBER) {
$ret = self::sendViber($options['viber'], $text) ;
}
if(strlen($chat_id)>0 && $sub->msg_type == self::MSG_BOT) {
$ret = self::sendBot($chat_id, $text, $sub->attach==1 ? $doc : null,$sub->html==1) ;
if(strlen($options['chat_id'])>0 && $this->msg_type == self::MSG_BOT) {
$ret = self::sendBot($options['chat_id'], $text, $this->attach==1 ? $options['doc'] : null,$this->html==1) ;
}
if($sub->reciever_type == self::RSV_WH) {
$ret = self::sendHook($sub->url, $text) ;
$ret = self::sendHook($this->url, $text) ;
}

if(strlen($ret)>0) {
Expand All @@ -245,23 +299,34 @@ public static function onDocumentState($doc_id, $state) {
$n->message = $ret;

$n->save();
return;
}

if ($sub->reciever_type != self::RSV_SYSTEM ){

// $text="Event: Документ ".$doc->meta_desc . "({$doc->document_number}) ";

// $text .= (' Стан ' .\App\Entity\Doc\Document::getStateName($doc->state) );

// self::sendNotify(\App\Entity\Notify::SYSTEM, $text);
}


}
}

/**
* возвращает текст с учетом разметки
*
* @param mixed $c
*/
private function getTextCust($c) {
$this->msgtext = str_replace('{', '{{', $this->msgtext);
$this->msgtext = str_replace('}', '}}', $this->msgtext);
$common = \App\System::getOptions("common");

}
}
$header = array();
$header['customer_id'] = $c->customer_id;
$header['customer_name'] = $c->customer_name;


try {
$m = new \Mustache_Engine();
$text = $m->render($this->msgtext, $header);

return $text;
} catch(\Exception $e) {
return "Помилка розмітки";
}
}
/**
* возвращает текст с учетом разметки
*
Expand Down
10 changes: 2 additions & 8 deletions www/app/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,7 @@ public static function addFile($file, $itemid, $comment, $itemtype = 0) {
$data = file_get_contents($file['tmp_name']);


if($conn->dataProvider=='postgres') {
$data = pg_escape_bytea($data);

}

$data = $conn->qstr($data);
$sql = "insert into filesdata (file_id,filedata) values ({$id},{$data}) ";
$conn->Execute($sql);
Expand Down Expand Up @@ -1329,10 +1326,7 @@ public static function checkVer(){
$phpv = phpversion() ;
$conn = \ZDB\DB::getConnect();

if($conn->dataProvider=="postgres") {
$phpv = $phpv. '_pg';
}



$nocache= "?t=" . time()."&s=". self::getSalt().'&phpv='.$phpv;

Expand Down
12 changes: 2 additions & 10 deletions www/app/modules/hr/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,7 @@ public function onCheck($sender) {
$image->content = $im;
$image->mime = $imagedata['mime'];

if($conn->dataProvider=='postgres') {
$image->thumb = pg_escape_bytea($image->thumb);
$image->content = pg_escape_bytea($image->content);

}

$image->save();
$c->image_id = $image->image_id;
$c->save();
Expand Down Expand Up @@ -456,11 +452,7 @@ public function importOnSubmit($sender) {
$image->content = $im;
$image->mime = $imagedata['mime'];

if($conn->dataProvider=='postgres') {
$image->thumb = pg_escape_bytea($image->thumb);
$image->content = pg_escape_bytea($image->content);

}

$image->save();
$item->image_id = $image->image_id;
break;
Expand Down
7 changes: 1 addition & 6 deletions www/app/modules/ocstore/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,7 @@ public function importOnSubmit($sender) {
$image = new \App\Entity\Image();
$image->content = $im;
$image->mime = $imagedata['mime'];
$conn = \ZDB\DB::getConnect();
if($conn->dataProvider=='postgres') {
$image->thumb = pg_escape_bytea($image->thumb);
$image->content = pg_escape_bytea($image->content);

}


$image->save();
$item->image_id = $image->image_id;
Expand Down
Loading

0 comments on commit e55a055

Please sign in to comment.