Ejemplo n.º 1
0
 protected function createStatement(\Lrs $lrs, \Client $client, array $statement)
 {
     $model = new \Statement(['lrs_id' => new \MongoId($lrs->_id), 'client_id' => $client->_id, 'statement' => $statement, 'active' => true, 'voided' => false, 'refs' => []]);
     $model->timestamp = new \MongoDate(strtotime($model->statement['timestamp']));
     $model->save();
     return $model;
 }
Ejemplo n.º 2
0
 public function gerenateMonthly()
 {
     $input = Input::all();
     $v = Validator::make(Input::All(), array('houseID' => 'required', 'propertyid' => 'required', 'agent_id' => 'required'));
     if ($v->passes()) {
         $propertyidan = Input::get('propertyid');
         $houseID = Input::get('houseID');
         $startDate = time();
         $lastmonth = date('Y-m-d', strtotime('+5 day', $startDate));
         $ddate = date('d');
         $agent_id = Input::get('agent_id');
         $billedusr = User::find($agent_id);
         $hisBalance = $billedusr->credit_balance;
         $newBalance = $hisBalance - 3;
         $billedusr->credit_balance = $newBalance;
         $billedusr->save();
         $billstatement = new Statement();
         $billstatement->type = "Generating Invoice";
         $billstatement->amount = 3;
         $billstatement->save();
         if ($houseID === "All") {
             $houses = House::where('status', '=', 'booked')->where('frequency', '=', 1)->where('propertyID', $propertyidan)->get();
             foreach ($houses as $house) {
                 $hid = $house->id;
                 $houseName = $house->name;
                 $propid = $house->propertyID;
                 $propname = Property::where('id', $propid)->pluck('name');
                 $rent = $house->rent;
                 $water = $house->water;
                 $garbage = $house->garbage;
                 $electricity = $house->electricity;
                 $security = $house->security;
                 $frequency = $house->frequency;
                 $tenant_id = $house->tenant;
                 $tenantnames = strtok($tenant_id, " ");
                 $tenant = Tenant::where('name', $tenantnames)->first();
                 $t_name = $tenant->name;
                 $to = $tenant->phone;
                 $t_agent = $tenant->agent_id;
                 $balance = $rent + $water + $garbage + $electricity + $security;
                 $invoice = new Invoice();
                 $invoice->type = 'to tenant';
                 $invoice->houseID = $houseName;
                 $invoice->recipient = $t_name;
                 $invoice->agent_id = $t_agent;
                 $invoice->balance = $balance;
                 $invoice->propertyid = $propid;
                 $invoice->duedate = $lastmonth;
                 $invoice->save();
                 $invoicedetail = new Invoicedetail();
                 $invoicedetail->rent = $rent;
                 $invoicedetail->water = $water;
                 $invoicedetail->garbage = $garbage;
                 $invoicedetail->electricity = $electricity;
                 $invoicedetail->security = $security;
                 $invoice->invoicedetail()->save($invoicedetail);
                 $message = 'Dear ' . $t_name . ', your rent for this month of Ksh ' . number_format($balance, 2) . '  is due for payment. For inquiries contact 0700548168 Rehema House Ngong';
                 Queue::push('SendSMS', array('message' => $message, 'number' => $to));
             }
             $noteSuccesGen = array('error' => false, 'message' => "Monthly invoice(s) generated successfully");
             return $noteSuccesGen;
         } else {
             $house = House::where('name', '=', $houseID)->where('frequency', '=', 1)->first();
             $hid = $house->id;
             $houseName = $house->name;
             $propid = $house->propertyID;
             $propname = Property::where('id', $propid)->pluck('name');
             $rent = $house->rent;
             $water = $house->water;
             $garbage = $house->garbage;
             $electricity = $house->electricity;
             $security = $house->security;
             $frequency = $house->frequency;
             $tenant_id = $house->tenant;
             $tenantnames = strtok($tenant_id, " ");
             $tenant = Tenant::where('name', $tenantnames)->first();
             $t_name = $tenant->name;
             $to = $tenant->phone;
             $t_agent = $tenant->agent_id;
             $balance = $rent + $water + $garbage + $electricity + $security;
             $invoice = new Invoice();
             $invoice->type = 'to tenant';
             $invoice->houseID = $houseName;
             $invoice->recipient = $t_name;
             $invoice->agent_id = $t_agent;
             $invoice->balance = $balance;
             $invoice->propertyid = $propid;
             $invoice->duedate = $lastmonth;
             $invoice->save();
             $invoicedetail = new Invoicedetail();
             $invoicedetail->rent = $rent;
             $invoicedetail->water = $water;
             $invoicedetail->garbage = $garbage;
             $invoicedetail->electricity = $electricity;
             $invoicedetail->security = $security;
             $invoice->invoicedetail()->save($invoicedetail);
             $message = 'Dear ' . $t_name . ', your rent for this month of Ksh ' . number_format($balance, 2) . '  is due for payment.For inquiries contact 0700548168 Rehema House Ngong';
             Queue::push('SendSMS', array('message' => $message, 'number' => $to));
             $noteSuccesGen = array('error' => false, 'message' => "Monthly invoice(s) generated successfully");
             return $noteSuccesGen;
         }
     }
     $noteGenerate4 = array('error' => true, 'message' => $v->messages());
     return $noteGenerate4;
 }
Ejemplo n.º 3
0
 protected static function updateDBByData(&$arrData)
 {
     $arrLog = [];
     Yii::log("updateDBByData start", "info");
     foreach ($arrData as $k => $v) {
         // найти запись в {{company}}
         // блокировка её FOR UPDATE
         $Company = Company::model()->findByAttributes(['INN' => $v['inn']]);
         if (!is_null($Company)) {
             $transaction = Yii::app()->getDb()->beginTransaction();
             try {
                 C2goActiveRecord::logStart();
                 $sqlCompanyBlock = 'SELECT * FROM ' . $Company->tableName() . ' WHERE `id`=:id  FOR UPDATE';
                 $CompanyById = Company::model()->findBySql($sqlCompanyBlock, ['id' => $Company->id]);
                 //$sqlCheckStatementExist = 'SELECT * FROM {{statement}} WHERE `tnd`=:tnd AND `sum`=:sum AND `inn`=:inn AND `date`=:date';
                 $arrParams = ['tnd' => $v['tnd'], 'sum' => $v['sum'], 'date' => static::convertXMLDate($v['date']), 'inn' => $v['inn']];
                 $StatementCheck = Statement::model()->findByAttributes($arrParams);
                 if (is_null($StatementCheck)) {
                     // добавить
                     $Statement = new Statement();
                     $Statement->tnd = $v['tnd'];
                     $Statement->sum = $v['sum'];
                     $Statement->date = static::convertXMLDate($v['date']);
                     $Statement->inn = $v['inn'];
                     $Statement->name = $v['name'];
                     if (!$Statement->save()) {
                         throw new CException(Yii::t('StatementModule.default', 'Не могу сохранить запись в Statement,errors', ['errors' => print_r($Statement->getErrors(), true)]));
                     }
                     Yii::log("updateDBByData p3 ", "info");
                     //@todo: log.processed
                     static::addToStatementLog($Statement, StatementLog::PROCESSED, $CompanyById);
                     Yii::log("updateDBByData p4 ", "info");
                     // verify
                     if (!$CompanyById->verify || !$CompanyById->validate) {
                         $CompanyById->verify = 1;
                         $CompanyById->validate = 1;
                         if ($CompanyById->save()) {
                             //@todo: log.verified
                             static::addToStatementLog($Statement, StatementLog::VERIFIED, $CompanyById);
                         } else {
                             throw new CException(Yii::t('StatementModule.default', 'Не могу в Company сделать verify=1,validate=1 ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
                         }
                     }
                     // company.balance
                     $CompanyById->balance += $v['sum'];
                     if ($CompanyById->save()) {
                         $AccountMotion = new AccountMotion();
                         $AccountMotion->company_id = $CompanyById->id;
                         $AccountMotion->price = $v['sum'];
                         $AccountMotion->notice = "import statement Statement.id=[{$Statement->id}]";
                         if ($AccountMotion->save()) {
                             //@todo: log.enrolled
                             static::addToStatementLog($Statement, StatementLog::ENROLLED, $CompanyById);
                             //sleep(5);
                             $transaction->commit();
                             $arrLog[] = ['success'];
                             C2goActiveRecord::logEndAndWrite();
                         } else {
                             throw new CException(Yii::t('StatementModule.default', 'Не могу добавить в AccountMotion ,errors', ['errors' => print_r($AccountMotion->getErrors(), true)]));
                         }
                     } else {
                         throw new CException(Yii::t('StatementModule.default', 'Не могу в Company изменить balance ,errors', ['errors' => print_r($CompanyById->getErrors(), true)]));
                     }
                 } else {
                     throw new CException(Yii::t('StatementModule.default', 'Statement запись уже есть'));
                 }
             } catch (Exception $e) {
                 $transaction->rollback();
                 $strException = $e->__toString();
                 Yii::log("updateDBByData exception [{$strException}]", "error");
                 $arrLog[] = ['error', $e->getMessage()];
                 C2goActiveRecord::logEmptyMessages();
             } finally {
                 C2goActiveRecord::logEnd();
             }
         } else {
             $arrLog[] = ['error', Yii::t('StatementModule.default', 'Не найдена компания по INN, inn_value', ['inn_value' => $v['inn']])];
         }
         //@todo: delete
         //break;
     }
     Yii::log("updateDBByData end", "info");
     return $arrLog;
 }
Ejemplo n.º 4
0
 public function loopStatements($statements)
 {
     //build new statements
     foreach ($statements as $s) {
         if (isset($s->context['extensions']['http://learninglocker&46;net/extensions/lrs'][1])) {
             $setlrs = $s->context['extensions']['http://learninglocker&46;net/extensions/lrs'][1];
         } elseif (isset($s->context['extensions']['http://learninglocker&46;net/extensions/lrs'][0])) {
             $setlrs = $s->context['extensions']['http://learninglocker&46;net/extensions/lrs'][0];
         } elseif (isset($s->context['extensions']['http://learninglocker&46;net/extensions/lrs'])) {
             $setlrs = $s->context['extensions']['http://learninglocker&46;net/extensions/lrs'];
         } else {
             $setlrs = $s->context['extensions']['http://learninglocker.net/extensions/lrs'];
         }
         //set statement
         if (isset($s->id)) {
             $set_statement['id'] = $s->id;
         }
         if (isset($s->actor)) {
             $set_statement['actor'] = $s->actor;
         }
         if (isset($s->verb)) {
             $set_statement['verb'] = $s->verb;
         }
         if (isset($s->object)) {
             $set_statement['object'] = $s->object;
         }
         if (isset($s->stored)) {
             $set_statement['stored'] = $s->stored;
         }
         if (isset($s->context)) {
             $context = $s->context;
             unset($context['extensions']['http://learninglocker&46;net/extensions/lrs']);
             unset($context['extensions']['http://learninglocker&46;net/extensions/category']);
             if (empty($context['extensions'])) {
                 unset($context['extensions']);
             }
             if (!empty($context)) {
                 $set_statement['context'] = $context;
             }
         }
         if (isset($s->result)) {
             $set_statement['result'] = $s->result;
         }
         if (isset($s->timestamp)) {
             $set_statement['timestamp'] = $s->timestamp;
         } else {
             $set_statement['timestamp'] = $s->stored;
         }
         if (isset($s->version)) {
             $set_statement['version'] = $s->version;
         }
         if (isset($s->attachments)) {
             $set_statement['attachments'] = $s->attachments;
         }
         //insert record to our new collection
         $statement = new Statement();
         $statement->lrs = (object) $setlrs;
         $statement->statement = $set_statement;
         $statement->created_at = $s->created_at;
         $statement->updated_at = $s->updated_at;
         $statement->save();
     }
 }