public function SaveByOpChange(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->setComment($state_name); $obj->setAction_date($state_change); $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 RejectChequeWithGastos(Gyuser_Model_Cheques $obj) { try { $chequeDetails = $this->FindWithOperationNames($obj); $amount = (int) $this->GetAmounByChequeId($obj); $gastos = (int) $obj->getRejected_gastos(); $gastos_type = $obj->getRejected_type(); $rejectedCostProv = 'null'; if ($chequeDetails->getLiquidacion_id()) { //the cheque has been passed to a provider $provMapper = new Gyuser_Model_ProvidersDataMapper(); $prov = $provMapper->GetProviderByIdSimple($chequeDetails->getProvider_id()); if ($gastos_type == "Denuncia") { $rejectedCostProv = $prov->getGastos_denuncia(); } elseif ($gastos_type == "Sin Fondos") { $rejectedCostProv = $prov->getGastos_rechazo(); } /* if ($chequeDetails->getCave_id()) { //the cave id property checks the provider_id field on DB, if it's not null then it's from a provider. $supMapper = new Gyuser_Model_SupplierOperationsDataMapper(); $supObj = new Gyuser_Model_SupplierOperations(); $supObj->setId($chequeDetails->getCave_id()); $supList = $supMapper->GetCaveById($supObj); //looks for provider id (not cave) if ($gastos_type == "Denuncia") $rejectedCostProv = $supList->getGastos_denuncia(); elseif ($gastos_type == "Sin Fondos") $rejectedCostProv = $supList->getGastos_rechazo(); } else { //it's from lavalle $caveMapper = new Gyuser_Model_OtherCavesDataMapper(); $caves = new Gyuser_Model_OtherCaves(); $caves->setId('1'); //lavalle $lavalle = $caveMapper->GetCaveById($caves); $x = 1; if ($gastos_type == "Denuncia") { $x = 1; $rejectedCostProv = $lavalle->getGastos_denuncia(); } elseif ($gastos_type == "Sin Fondos") { $rejectedCostProv = $lavalle->getGastos_rechazo(); } } * */ } $amount = $amount + $gastos; $data = array('status' => 3, 'balance' => $amount, 'rejected_cost' => $gastos, 'rejected_type' => $gastos_type, 'rejected_cost_prov' => $rejectedCostProv); $success = $this->getDbTable()->update($data, array('id = ?' => $obj->getId())); if ($success) { $opId = $this->GetChequeOpId($obj->getId()); //update op status to 11 = 'En Cobranza' $opMapper = new Gyuser_Model_OperationsDataMapper(); $opMapper->setOperationEnCobranza($opId); $clientMapper = new Gyuser_Model_UserDataMapper(); $clientId = $clientMapper->getClientByChequeId($obj->getId()); if ($clientId) { $client = new Gyuser_Model_User(); $client->setId($clientId); $client->setClient_type(4); $clientMapper->UpdateUserType($client); } else { throw new Exception('The cheque status was updated to rejected but the client type could not be updated (to 4 = cobranza)'); } //$chequeDetails = $this->FindWithOperationNames($obj); $mapper = new Gyuser_Model_NotificationsDataMapper(); $obj = new Gyuser_Model_Notifications(); $obj->setTitle('Cheque rechazado'); $Operation_id = $chequeDetails->getOperation_id(); $check_n = $chequeDetails->getCheck_n(); $check_date = $chequeDetails->getDate(); $operator_id = $request->operator_id; $obj->setOperator_id($Operation_id); $obj->setComment("El cheque {$check_n} con fecha {$check_date} op.{$Operation_id} fue rechazado por {$gastos_type}"); $obj->setAction_date(date('Y-m-d h:i:s')); $result = $mapper->SaveWhenRejected($obj); } else { throw new Exception('There was an error updating the cheques table'); } return $result; } catch (Exception $e) { echo $e; } }