Ejemplo n.º 1
0
 public function editDepositBySender($data)
 {
     $db = $this->getAdapter();
     $db->beginTransaction();
     try {
         //     		$where = 'id = '.$data['tran_id'];
         //     		$ss = $this->delete($where);
         $session_user = new Zend_Session_Namespace('auth');
         $user_id = $session_user->user_id;
         $arr = array('invoice' => $data['invoice_no'], 'sender_id' => $data['sender'], 'pay_term' => $data['pay_term'], 'start_date' => $data['send_date'], 'end_date' => $data['epx_date'], 'amount_month' => $data['amount_month'], 'money_type' => $data['type_money'], 'money_inaccount' => $data['money_inacc'], 'money_inaccount_org' => $data['money_inacc'], 'commission' => $data['commission'], 'total_amount' => $data['total_amount'], 'recieve_amount' => $data['recieve_amount'], 'total_return' => $data['total_amount'], 'recieve_province' => $data['province'], 'agent_id' => $data['agent_id'], 'sub_agent_id' => $data['sub_agent_id'], 'status' => 1, 'user_id' => $user_id);
         //     		$this->insert($arr);
         $where = 'id = ' . $data['tran_id'];
         $this->update($arr, $where);
         $dbc = new Application_Model_DbTable_DbCapital();
         $rs = $this->getCapitalDetailById($data['tran_id'], 4);
         if (!empty($rs)) {
             if ($rs['curr_type'] == $data['type_money'] and $rs['amount'] != $data['total_amount']) {
                 //if the same currency type
                 $amount = $data['total_amount'] - $rs['amount'];
                 $rs_cap = $dbc->DetechCapitalExist($user_id, $data['type_money'], null);
                 if (!empty($rs_cap)) {
                     //update new user
                     $arr = array('amount' => $rs_cap['amount'] + $amount);
                     $dbc->updateCurrentBalanceById($rs_cap['id'], $arr);
                 } else {
                     $date = date("Y-m-d H:i:s");
                     //change it to current edit
                     $arr = array('amount' => $data['total_amount'], 'currencyType' => $data['type_money'], 'userid' => $user_id, 'statusDate' => $date);
                     $dbc->AddCurrentBalanceById($arr);
                 }
             } else {
                 if ($rs['curr_type'] != $data['type_money']) {
                     //if edit change currency type
                     $rs_cap = $dbc->DetechCapitalExist($user_id, $rs['curr_type'], null);
                     //with old currency
                     $amount = $rs_cap['amount'] - $rs['amount'];
                     //ot trov pls check again
                     $arr = array('amount' => $amount);
                     $dbc->updateCurrentBalanceById($rs_cap['id'], $arr);
                     //to reset old record
                     $rs_cap = $dbc->DetechCapitalExist($user_id, $data['type_money'], null);
                     //with new currency
                     if (!empty($rs_cap)) {
                         //update old user
                         $arr = array('amount' => $rs_cap['amount'] + $data['total_amount']);
                         $dbc->updateCurrentBalanceById($rs_cap['id'], $arr);
                     } else {
                         $date = date("Y-m-d H:i:s");
                         $arr = array('amount' => $data['total_amount'], 'currencyType' => $data['type_money'], 'userid' => $user_id, 'statusDate' => $date);
                         $dbc->AddCurrentBalanceById($arr);
                     }
                 }
             }
             $_arr = array('tran_type' => 4, 'curr_type' => $data['type_money'], 'amount' => $data['total_amount'], 'user_id' => $user_id);
             $dbc->updateCapitalDetailById($rs['id'], $_arr);
         }
         $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
     }
 }
Ejemplo n.º 2
0
 public function culToCapitalDelete($tran_id, $currency_type, $amount)
 {
     /*start insert to capital*/
     $session_user = new Zend_Session_Namespace('auth');
     $user_id = $session_user->user_id;
     $db_cap = new Application_Model_DbTable_DbCapital();
     $cd = $db_cap->getCapitalDetailById($tran_id, 6, $currency_type);
     $date = date_create($cd['date']);
     $day = date_format($date, "d/m/Y");
     $rs = $db_cap->DetechCapitalExist($user_id, $currency_type, $day);
     //check if add capital exist
     if (!empty($rs)) {
         $arr = array('amount' => $rs['amount'] - $amount);
         $db_cap->updateCurrentBalanceById($rs['id'], $arr);
     }
     //update to capital_detail
     $db_cap->updateCapitalDetailById($cd['id'], array('status' => '0'));
     /*end update to capital*/
 }
Ejemplo n.º 3
0
 /**
  * Update For data exchange
  * @param Array $data
  * @return number
  */
 function updateData($data)
 {
     $db_cap = new Application_Model_DbTable_DbCapital();
     $session_user = new Zend_Session_Namespace('auth');
     $to_type = $this->getCurrencyById("`name`, `symbol`,`country_id`", $data["to_amount_type"]);
     $from_type = $this->getCurrencyById("`name`, `symbol`,`country_id`", $data["from_amount_type"]);
     $status = "in";
     if ($data["from_amount_type"] == 2 && $data["to_amount_type"] == 1 || $data["from_amount_type"] == 3) {
         $status = "out";
     }
     $_data = array("changedAmount" => $data["return_money"], "specail_customer" => empty($data['special_cus']) ? 0 : 1, "toAmount" => $data["to_amount"], "toAmountType" => $to_type["symbol"], "rate" => $data["rate"], "fromAmountType" => $from_type["symbol"], "fromAmount" => $data["from_amount"], "recievedType" => $from_type["symbol"], "recievedAmount" => $data["recieve_money"], "statusDate" => date('Y-m-d H:i:s'), "userid" => $session_user->user_id, "status" => $status, "from_to" => $from_type['name'] . " - " . $to_type["name"]);
     $result = $this->getDataById($data['id']);
     $user_id = $session_user->user_id;
     $db = $this->getAdapter();
     $db->beginTransaction();
     try {
         if ($result) {
             if ($data['from_amount'] != $result['fromAmount']) {
                 //if amount has changed
                 //update to capital_detail
                 $arr_cdfrom = array('curr_type' => $data["from_amount_type"], 'amount' => $data["from_amount"], 'date' => date('Y-m-d'));
                 $capital_detail = $db_cap->getCapitalDetailById($data['id'], 3, $data["from_amount_type"]);
                 $db_cap->updateCapitalDetailById($capital_detail['id'], $arr_cdfrom);
                 $arr_cdto = array('curr_type' => $data["to_amount_type"], 'amount' => $data["to_amount"], 'date' => date('Y-m-d'));
                 $capital_detail = $db_cap->getCapitalDetailById($data['id'], 3, $data["to_amount_type"]);
                 $db_cap->updateCapitalDetailById($capital_detail['id'], $arr_cdto);
                 //*************************************************************
                 //update to cs_current_capital
                 $amount = $data["from_amount"] - $data["return_money"];
                 $to = $data['to_amount'] - $result['toAmount'];
                 $from = $amount - $result['fromAmount'];
                 $currency_type_from = $data["from_amount_type"];
                 $currency_type_to = $data["to_amount_type"];
                 // 			    		print_r($_data);echo "**data<br/>";
                 // 			    		print_r($result);echo "**result<br/>";
                 // 			    		echo "to=".$to."<br/>from=".$from."<br/>amount=".$amount."<br/>";
                 // 		    		echo $amount." *** ".$amount_to;
                 // 		    		exit;
                 //from amount
                 $rs = $db_cap->DetechCapitalExist($user_id, $currency_type_from, null);
                 //check if add capital exist
                 // 			    		print_r($rs);echo "***rs from<br/>";
                 if (!empty($rs)) {
                     $balan = $rs['amount'] - abs($from);
                     if ($from > 0) {
                         $balan = $rs['amount'] + abs($from);
                     }
                     $arr = array('amount' => $balan);
                     $db_cap->updateCurrentBalanceById($rs['id'], $arr);
                 } else {
                     $arr = array('amount' => $data["from_amount"], 'currencyType' => $currency_type_from, 'userid' => $user_id, 'statusDate' => date("Y-m-d H:i:s"));
                     $db_cap->AddCurrentBalanceById($arr);
                 }
                 // 			    		print_r($arr);echo "**arr from<br/>";
                 //end from amount
                 //to amount
                 $rs = $db_cap->DetechCapitalExist($user_id, $currency_type_to, null);
                 //check if add capital exist
                 // 			    		print_r($rs);echo "***rs to<br/>";
                 if (!empty($rs)) {
                     $balan = $rs['amount'] + abs($to);
                     if ($from > 0) {
                         $balan = $rs['amount'] - abs($to);
                     }
                     $arr = array('amount' => $balan);
                     $db_cap->updateCurrentBalanceById($rs['id'], $arr);
                 } else {
                     $arr = array('amount' => -$data['to_amount'], 'currencyType' => $currency_type_to, 'userid' => $user_id, 'statusDate' => date("Y-m-d H:i:s"));
                     $db_cap->AddCurrentBalanceById($arr);
                 }
                 // 			    		print_r($arr);echo "**arr to<br/>";exit;
                 //end to amount
             }
             $this->_name = 'cs_exchange';
             $where = $this->getAdapter()->quoteInto('id=?', $data['id']);
             $this->update($_data, $where);
         }
         //     	return  $this->update($_data, $where);
         return $db->commit();
     } catch (Exception $e) {
         $db->rollBack();
     }
 }