public function SaveWhenRejected(Gyuser_Model_Notifications $obj) { $opMapper = new Gyuser_Model_OperationsDataMapper(); $opObj = new Gyuser_Model_Operations(); $opObj->setId($obj->getOperator_id()); $opResult = $opMapper->GetStateByOperationId($opObj); if ($opResult) { $state_name = $opResult['state_name']; $state_change = $opResult['state_change']; $client_id = $opResult['client_id']; $obj->setClient_id($client_id); } $sessionNamespace = new Zend_Session_Namespace(); $operatorId = null; if ($sessionNamespace->loginAuth == true) { $authDetail = $sessionNamespace->authDetail; $operatorId = $authDetail->getId(); } $data = array('title' => $obj->getTitle(), 'comment' => $obj->getComment(), 'operator_id' => $operatorId, 'action_date' => $obj->getAction_date(), 'client_id' => $obj->getClient_id()); if (null === ($id = $obj->getId())) { unset($data['id']); $id = $this->getDbTable()->insert($data); return $id; } else { unset($data['operation_id']); $id = $this->getDbTable()->update($data, array('id = ?' => $id)); return $id; } }
public function getchecksbyoperationidajaxAction() { try { $request = $this->getRequest(); if ($this->getRequest()->isPost()) { $operationid = $request->operation_id; $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $mapper = new Gyuser_Model_OperationsDataMapper(); $obj = new Gyuser_Model_Operations(); $obj->setId($operationid); $planid = $mapper->GetPlanIdByOperationId($obj); $interests_id = $mapper->GetInterestsIdByOperationId($obj); $mapper = new Gyuser_Model_ChequesDataMapper(); $chequesList = $mapper->GetChequeDetailsByOpId($operationid); $result['planid'] = $planid; $result['interests_id'] = $interests_id; $result['cheques'] = $chequesList; if ($result) { echo json_encode($result); } else { echo "f"; } } } catch (Exception $e) { echo $e; } }
public function createliquidacionAction() { try { $request = $this->getRequest(); if ($this->getRequest()->isPost()) { $liqDataId = 0; $liqId = (int) $request->id; //if there's an empty string it defaults to 0 $liqDate = $request->date; $variableDate = false; $lMapper = new Gyuser_Model_LiquidacionesDataMapper(); $liq = new Gyuser_Model_Liquidaciones(); $liq->setProvider_id($request->provider_id); $liq->setCommitted((int) $request->committed); $pMapper = new Gyuser_Model_ProvidersDataMapper(); $prov = $pMapper->GetProviderById($liq->getProvider_id()); $cMapper = new Gyuser_Model_ChequesDataMapper(); $oMapper = new Gyuser_Model_OperationsDataMapper(); //if liq has already been submitted then cleanup previous //selected cheques, rejected cheques and operations if ($liqId) { $chequesList = $cMapper->UpdateLiquidacionDeleted($liqId); $opertationsList = $oMapper->UpdateLiquidacionDeleted($liqId); } else { $liqId = $lMapper->createNewLiq(); } //check liq id has been created. if ($liqId) { $liq->setId($liqId); //depending on the status of the liquidacion //set the appropriate dates and/or liq data if ($liq->getCommitted() == 0) { //set current date and current prov values list($Day, $Month, $Year) = explode('/', $liqDate); $liqDate = mktime(12, 0, 0, $Month, $Day, $Year); $liqDate = date("Y-m-d", $liqDate); $today = date("Y-m-d"); if ($liqDate != $today) { $liq->setDate($liqDate); $variableDate = true; } else { $liq->setDate($today); } //even if this date won't be stored in db, we needed to calculate checks today value $provData = $prov; //set the current provider values as prov data } elseif ($liq->getCommitted() == 2) { //status is en camino. save date and prov values $liqData = $lMapper->GetLiquidacionesById($liq); //set date as today or as date selected by user if ($liqData['variable_date']) { $liq->setDate($liqData['date']); $variableDate = true; } else { $liq->setDate(date('Y-m-d')); } //set current prov values into liq for db save $liq->setTasa_anual($prov->getTasa_anual()); $liq->setImpuesto_al_cheque($prov->getImpuesto_al_cheque()); $liq->setAcreditacion_capital($prov->getAcreditacion_capital()); $liq->setAcreditacion_interior($prov->getAcreditacion_interior()); $liq->setGastos_general($prov->getGastos_general()); $liq->setGastos_interior($prov->getGastos_interior()); $liq->setGastos_cheque_a_1($prov->getGastos_cheque_a_1()); $liq->setGastos_cheque_menor_a_1($prov->getGastos_cheque_menor_a_1()); $liq->setGastos_cheque_a_2($prov->getGastos_cheque_a_2()); $liq->setGastos_cheque_menor_a_2($prov->getGastos_cheque_menor_a_2()); $liq->setDate_delivered(date("Y-m-d")); $provData = $prov; //set the current provider values as prov data } elseif ($liq->getCommitted() == 1) { //to be consolidated get the prov values stored in liq $liqData = $lMapper->GetLiquidacionesById($liq); //set date as date saved on step 2 $liq->setDate($liqData['date']); $provData = $lMapper->getProvData($liqId); //set the saved prov data on liq to calculate checks values } /* update Liquidacion id in cheques */ $checksJson = json_decode($request->cheques_json); $checkObj = new Gyuser_Model_Cheques(); $checkObj->setLiquidacion_id($liqId); $checkObj->setProvider_id($liq->getProvider_id()); foreach ($checksJson as $check) { $checkObj->setId($check->cheque_id); if ($check->acreditacion_hrs) { $checkObj->setAcreditacion_hrs($check->acreditacion_hrs); } $cMapper->UpdateLiquidacion($checkObj); } /* update Liquidacion id in rejected cheques */ $rejected_cheques_json = json_decode($request->rejected_cheques_json); $rejCheckTotal = 0; foreach ($rejected_cheques_json as $check) { $checkDetails = $cMapper->getCheckDetails($check->rejected_cheque_id); $gastos_type = $checkDetails->getRejected_type(); if ($gastos_type == "Denuncia") { $checkDetails->setRejected_cost_prov($prov->getGastos_denuncia()); } elseif ($gastos_type == "Sin Fondos") { $checkDetails->setRejected_cost_prov($prov->getGastos_rechazo()); } //set the current liq id as the liq id where the rejected check was payed $checkDetails->setRejected_liq_id($liqId); //add the check total to the rej checks total $rejCheckTotal += $checkDetails->getAmount() + $checkDetails->getRejected_cost_prov(); $cMapper->UpdateRejectedCheques($checkDetails); } $opsTotal = 0; /* update Liquidacion id in operations */ $operations_json = json_decode($request->operations_json); $opDetails = new Gyuser_Model_Operations(); $opDetails->setLiquidacion_id($liqId); $commissionRate = $prov->getComisionRate(); foreach ($operations_json as $operation) { $opDetails->setId($operation->operation_id); $oMapper->UpdateLiquidacion($opDetails); $amount = (double) $oMapper->GetAmount($operation->operation_id); $commissionAmt = (double) $pMapper->calculateComisionAmt($amount, $commissionRate); $opsTotal += (double) $pMapper->calculateProvPayment($amount, $commissionAmt); } $checksTotals = $cMapper->GetChequesTotalsJson($liq->getProvider_id(), $checksJson, $provData, $liq->getDate()); $acreditacion = floatval($request->acreditacion); $amountDebt = $rejCheckTotal + $opsTotal - $acreditacion; $accountBalance = $checksTotals['payingAmount'] - $amountDebt; $liq->setId($liqId); $liq->setAcreditacion($acreditacion); $liq->setAmount_debt($amountDebt); $liq->setAmount_payed($checksTotals['payingAmount']); $liq->setPrevious_account_balance($prov->getBalance()); $liq->setCurrent_account_balance($accountBalance); $liq->setChecks_qty($checksTotals['chequeChkCount']); $liq->setAverage_days($checksTotals['dayAvg']); $liq->setTotal_bruto($checksTotals['bruto']); $liq->setImpuesto_al_cheque_amt($checksTotals['impuestoAlCheque']); //the amount for impuesto al cheque $liq->setIntereses($checksTotals['intereses']); //also called descuento $liq->setGastos_interior_fee($checksTotals['gastosInterior']); //the amount for interior gastos $liq->setGastos_general_fee($checksTotals['gastosGeneral']); //the amount for general gastos $liq->setGastos_varios($checksTotals['gastosOtros']); $liq->setTotal_neto($checksTotals['payingAmount']); $lMapper->createLiq($liq, $variableDate); //update current balance $prov->setBalance($accountBalance); $pMapper->UpdateBalance($prov); } else { throw new Exception('error inserting new liquidacion'); } $this->_helper->redirector('providers', 'liquidaciones', 'gyuser', array('provider_id' => $request->provider_id)); } } catch (Exception $e) { echo $e; } }
public function GetOperationsByProviderId($provider_id) { $table = $this->getDbTable(); $select = $table->select(); $select->setIntegrityCheck(false); $select->from(array('opr' => 'operations'), array('id', 'client_id', 'date', 'amount', 'observations', 'report', 'date_added', 'state_order_id', 'cave_id')); $select->joinLeft(array('prov' => 'providers'), 'opr.cave_id = prov.id', array('name as cave_name', 'comision_rate')); $select->joinLeft(array('cls' => 'clients'), 'opr.client_id = cls.id', array('first_name', 'last_name')); $select->where('opr.cave_id = ?', $provider_id); $select->where('opr.liquidacion_id IS NULL'); //NOTE! gus also wants to show the operations with state "En Lavalle". $select->where('opr.state_order_id = 8 OR opr.state_order_id = 9 OR opr.state_order_id = 10 OR opr.state_order_id = 11'); $select->order('opr.id ASC'); $resultSet = $table->fetchAll($select); $entries = array(); foreach ($resultSet as $row) { $entry = new Gyuser_Model_Operations(); $entry->setId($row->id); $entry->setClient_id($row->client_id); $entry->setDate(date("d/m/Y", strtotime($row->date))); $entry->setAmount($row->amount); $entry->setState($row->state_order_id); $entry->setObservations($row->observations); $entry->setReport($row->report); $entry->setProv_name($row->cave_name); $entry->setProv_commission_rate($row->comision_rate); $pMapper = new Gyuser_Model_ProvidersDataMapper(); $commissionAmt = $pMapper->calculateComisionAmt($row->amount, $row->comision_rate); $entry->setProv_commission_amt($commissionAmt); $provPayment = $pMapper->calculateProvPayment($row->amount, $commissionAmt); $entry->setProv_payment($provPayment); /* $provider_obj = new Gyuser_Model_Providers(); $provider_obj->setName($row->cave_name); $provider_obj->setComisionRate($row->comision_rate); $pMapper = new Gyuser_Model_ProvidersDataMapper(); $comisionAmt = $pMapper->calculateComisionAmt($row->amount, $row->comision_rate); $provPayment = $pMapper->calculateProvPayment($row->amount, $comisionAmt); $provider_obj->setComisionAmt($comisionAmt); $provider_obj->setProvPayment($provPayment); $entry->setProvider_obj($provider_obj); * */ $clientObj = new Gyuser_Model_User(); $clientObj->setFirst_name($row->first_name); $clientObj->setLast_name($row->last_name); $entry->setUser_obj($clientObj); $entries[] = $entry; } return $entries; }