示例#1
0
 public function actionLoad()
 {
     Payments::model()->deleteAll();
     Trucks::model()->deleteAll();
     ZReport::model()->deleteAll();
     $this->render("load");
 }
示例#2
0
 public function actionConfirm($id)
 {
     $payment = Payments::model()->findByPk($id);
     if ($payment) {
         $payment->complete();
     }
     if (!Yii::app()->request->isAjaxRequest) {
         $this->redirect(array('admin'));
     }
     Yii::app()->end();
 }
示例#3
0
    /**
     * Add document to binder
     * @param $docId
     */
    public static function addDocumentToBinder($docId)
    {
        $document = Documents::model()->findByPk($docId);
        if ($document) {
            $year = substr($document->Created, 0, 4);
            Storages::createProjectStorages($document->Project_ID, $year);
            $subsectionId = 0;
            if ($document->Document_Type == Documents::PM) {
                $payment = Payments::model()->findByAttributes(array(
                    'Document_ID' => $docId,
                ));
                $year = substr($payment->Payment_Check_Date, 0, 4);
                $subsectionId = Sections::createLogBinder($document->Project_ID, $document->Document_Type, $year);
            } elseif ($document->Document_Type == Documents::PO) {
                $po = Pos::model()->findByAttributes(array(
                    'Document_ID' => $docId,
                ));
                $year = substr($po->PO_Date, 0, 4);
                $subsectionId = Sections::createLogBinder($document->Project_ID, $document->Document_Type, $year);
                if ($po->PO_Backup_Document_ID != 0) {
                    $bu = LibraryDocs::model()->findByAttributes(array(
                        'Document_ID' => $po->PO_Backup_Document_ID,
                        'Subsection_ID' => $subsectionId,
                    ));
                    if (!$bu) {
                        $libDoc = new LibraryDocs();
                        $libDoc->Document_ID = $po->PO_Backup_Document_ID;
                        $libDoc->Subsection_ID = $subsectionId;
                        $libDoc->Access_Type = Storages::HAS_ACCESS;
                        $libDoc->Sort_Numb = 0;
                        if ($libDoc->validate()) {
                            $libDoc->save();
                        }
                    }
                }
            }

            $libDoc = LibraryDocs::model()->findByAttributes(array(
                'Document_ID' => $docId,
                'Subsection_ID' => $subsectionId,
            ));

            if (!$libDoc) {
                $libDoc = new LibraryDocs();
                $libDoc->Document_ID = $docId;
                $libDoc->Subsection_ID = $subsectionId;
                $libDoc->Access_Type = Storages::HAS_ACCESS;
                $libDoc->Sort_Numb = 0;
                if ($libDoc->validate()) {
                    $libDoc->save();
                }
            }

            LibraryDocs::sortDocumentsInSubsection($subsectionId);
        }
    }
示例#4
0
 public function loadModel($id)
 {
     $model = Payments::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#5
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         if (Payments::model()->count('order_id=' . $id) !== 0) {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 Contracts::model()->deleteAll('order_id=' . $id);
                 Acts::model()->deleteAll('order_id=' . $id);
                 Invoices::model()->deleteAll('order_id=' . $id);
                 InvoicesFkt::model()->deleteAll('order_id=' . $id);
                 Works::model()->deleteAll('order_id=' . $id);
                 $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' и документы по нему удалёны';
                 $model->delete();
                 $transaction->commit();
                 Yii::app()->user->setFlash('success', $msg);
                 Yii::app()->logger->write($msg);
             } catch (Exception $e) {
                 $transaction->rollBack();
                 $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' - удаление не удалось';
                 Yii::app()->user->setFlash('error', $msg);
                 Yii::app()->logger->write($msg);
             }
         } else {
             $msg = 'Заказ #' . $model->id . ' - ' . $model->name . ' для ' . $model->client->name . ' - удаление невозможно. По этому заказу уже были проведены платежи';
             Yii::app()->user->setFlash('notice', $msg);
             Yii::app()->logger->write($msg);
         }
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
示例#6
0
	/**
	 * Lists all models.
	 */
	public function actionIndex()
	{
        if (isset($_POST['oper']) && $_POST['oper'] == 'edit') {
            $paymentId = intval($_POST["id"]);
            $payment = Payments::model()->with('vendor')->findByPk($paymentId);

            if ($payment) {
                $vendor = $payment->vendor;
                $bank_account = $payment->bank_account;
                if ($vendor) {
                    $client = $vendor->client;
                    $company = $client->company;
                    $addresses = $company->adreses;

                    if (isset($addresses[0])) {
                        $address = $addresses[0];
                        $address->Address1 =  $_POST["Address1"];
                        $address->Address2 =  $_POST["Address2"];
                        $address->City =  $_POST["City"];
                        $address->State =  $_POST["State"];
                        $address->ZIP =  $_POST["ZIP"];
                        $address->Country =  $_POST["Country"];
                        $address->Phone =  $_POST["Phone"];
                        $address->Fax =  $_POST["Fax"];
                        if ($address->validate()) {
                            $address->save();
                            echo "adresses\n";
                        }
                    }

                    if ($company) {
                        $company->Company_Name = $_POST["Company_Name"];
                        $company->Company_Fed_ID = $_POST["Company_Fed_ID"];
                        $company->Email = $_POST["Email"];
                        $company->SSN = $_POST["SSN"];
                        $company->Business_NameW9 = $_POST["Business_NameW9"];
                        if ($company->validate()) {
                            $company->save();
                            echo "company\n";
                        }
                    }
                }

                if ($bank_account) {
                    $bank_account->Account_Number = $_POST["Account_Number"];
                    $bank_account->Account_Name = $_POST["Account_Name"];
                    $bank_account->Bank_Name = $_POST["Bank_Name"];
                    $bank_account->Bank_Routing = $_POST["Bank_Routing"];
                    $bank_account->Bank_SWIFT = $_POST["Bank_SWIFT"];
                    if ($bank_account->validate()) {
                        $bank_account->save();
                        echo "bank account\n";
                    }
                }

                $payment->Payment_Check_Date = $_POST["Payment_Check_Date"] ? $_POST["Payment_Check_Date"] : null;
                $payment->Payment_Check_Number = $_POST["Payment_Check_Number"] ? $_POST["Payment_Check_Number"] : null;
                $payment->Payment_Amount = $_POST["Payment_Amount"] ? $_POST["Payment_Amount"] : null;
                if ($payment->validate()) {
                    $payment->save();
                    echo "payment\n";
                }
            }

            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'add') {
            die;
        }

        if (isset($_POST['oper']) && $_POST['oper'] == 'del') {
            $paymentId = intval($_POST["id"]);
            $payment = Payments::model()->findByPk($paymentId);
            if ($payment) {
                Payments::deletePayment($paymentId);
            }
            die;
        }

        $conn = mysql_connect(Yii::app()->params->dbhost, Yii::app()->params->dbuser, Yii::app()->params->dbpassword);
        mysql_select_db(Yii::app()->params->dbname);
        mysql_query("SET NAMES 'utf8'");

        Yii::import('ext.phpgrid.inc.jqgrid');

        // set columns
        $col = array();
        $col["title"] = "Payment ID"; // caption of column
        $col["name"] = "Payment_ID";
        $col["dbname"] = "payments.Payment_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Document ID"; // caption of column
        $col["name"] = "Document_ID";
        $col["dbname"] = "payments.Document_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = true;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Payment Check Date"; // caption of column
        $col["name"] = "Payment_Check_Date";
        $col["dbname"] = "payments.Payment_Check_Date"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = true; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $col["formatter"] = "date";
        $col["formatoptions"] = array("srcformat"=>'Y-m-d',"newformat"=>'Y-m-d');
        $cols[] = $col;

        $col = array();
        $col["title"] = "Payment Check Number"; // caption of column
        $col["name"] = "Payment_Check_Number";
        $col["dbname"] = "payments.Payment_Check_Number"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = true; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Payment Amount"; // caption of column
        $col["name"] = "Payment_Amount";
        $col["dbname"] = "payments.Payment_Amount"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Account Number"; // caption of column
        $col["name"] = "Account_Number";
        $col["dbname"] = "bank_acct_nums.Account_Number"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Account Name"; // caption of column
        $col["name"] = "Account_Name";
        $col["dbname"] = "bank_acct_nums.Account_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Bank Name"; // caption of column
        $col["name"] = "Bank_Name";
        $col["dbname"] = "bank_acct_nums.Bank_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Bank Routing"; // caption of column
        $col["name"] = "Bank_Routing";
        $col["dbname"] = "bank_acct_nums.Bank_Routing"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Bank SWIFT"; // caption of column
        $col["name"] = "Bank_SWIFT";
        $col["dbname"] = "bank_acct_nums.Bank_SWIFT"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "File Name"; // caption of column
        $col["name"] = "File_Name";
        $col["dbname"] = "images.File_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["default"] = "<span class='image_view' data='{Document_ID}'>{File_Name}</span>";
        $cols[] = $col;

        $col = array();
        $col["title"] = "Mime Type"; // caption of column
        $col["name"] = "Mime_Type";
        $col["dbname"] = "images.Mime_Type"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company ID"; // caption of column
        $col["name"] = "Company_ID";
        $col["dbname"] = "companies.Company_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = false;
        $col["editable"] = false; // this column is editable
        $col["hidden"] = false;
        $col["viewable"] = true;
        $col["search"] = false;
        $col["sortable"] = false;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "Company Name"; // caption of column
        $col["name"] = "Company_Name";
        $col["dbname"] = "companies.Company_Name"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fed ID"; // caption of column
        $col["name"] = "Company_Fed_ID";
        $col["dbname"] = "companies.Company_Fed_ID"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        // set columns
        $col = array();
        $col["title"] = "SSN"; // caption of column
        $col["name"] = "SSN";
        $col["dbname"] = "companies.SSN"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = true;
        $col["sortable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Email"; // caption of column
        $col["name"] = "Email";
        $col["dbname"] = "companies.Email"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Business_NameW9"; // caption of column
        $col["name"] = "Business_NameW9";
        $col["dbname"] = "companies.Business_NameW9"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address1"; // caption of column
        $col["name"] = "Address1";
        $col["dbname"] = "addresses.Address1"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Address2"; // caption of column
        $col["name"] = "Address2";
        $col["dbname"] = "addresses.Address2"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "City"; // caption of column
        $col["name"] = "City";
        $col["dbname"] = "addresses.City"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "State"; // caption of column
        $col["name"] = "State";
        $col["dbname"] = "addresses.State"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "ZIP"; // caption of column
        $col["name"] = "ZIP";
        $col["dbname"] = "addresses.ZIP"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Country"; // caption of column
        $col["name"] = "Country";
        $col["dbname"] = "addresses.Country"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Phone"; // caption of column
        $col["name"] = "Phone";
        $col["dbname"] = "addresses.Phone"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $cols[] = $col;

        $col = array();
        $col["title"] = "Fax"; // caption of column
        $col["name"] = "Fax";
        $col["dbname"] = "addresses.Fax"; // grid column name, same as db field or alias from sql
        $col["resizable"] = true;
        $col["editable"] = true; // this column is editable
        $col["viewable"] = true;
        $col["search"] = false;
        $cols[] = $col;


        $g = new jqgrid();

        $grid["caption"] = "Payments";
       // $grid["multiselect"] = true;
        $grid["autowidth"] = true;
        $grid["resizable"] = true;
        //$grid["toppager"] = true;
        $grid["sortname"] = 'companies.Company_Name';
        $grid["sortorder"] = "ASC";
        $grid["add_options"] = array(
            'width'=>'420',
            "closeAfterEdit"=>true, // close dialog after add/edit
            "top"=>"200", // absolute top position of dialog
            "left"=>"200" // absolute left position of dialog
        );

        $g->set_options($grid);

        $g->set_actions(array(
                "add"=>false, // allow/disallow add
                "edit"=>true, // allow/disallow edit
                "delete"=>true, // allow/disallow delete
                "rowactions"=>true, // show/hide row wise edit/del/save option
                "export"=>true, // show/hide export to excel option
                "autofilter" => true, // show/hide autofilter for search
                "search" => "advance" // show single/multi field search condition (e.g. simple or advance)
            )
        );

        $g->select_command = "SELECT   companies.*, addresses.*,
                                       payments.*, bank_acct_nums.Account_Number, bank_acct_nums.Account_Name,
                                       bank_acct_nums.Bank_Name, bank_acct_nums.Bank_Routing, bank_acct_nums.Bank_SWIFT,
                                       images.File_Name, images.Mime_Type
                              FROM payments
                              LEFT JOIN documents ON documents.Document_ID = payments.Document_ID
                              LEFT JOIN images ON images.Document_ID = documents.Document_ID
                              LEFT JOIN bank_acct_nums ON bank_acct_nums.Account_Num_ID = payments.Account_Num_ID
                              LEFT JOIN vendors ON payments.Vendor_ID = vendors.Vendor_ID
                              LEFT JOIN clients ON clients.Client_ID = vendors.Vendor_Client_ID
                              LEFT JOIN companies ON clients.Company_ID = companies.Company_ID
                              LEFT JOIN company_addresses ON company_addresses.Company_ID = companies.Company_ID
                              LEFT JOIN addresses ON addresses.Address_ID = company_addresses.Address_ID";

        // set database table for CRUD operations
        $g->table = "payments";

        $g->set_columns($cols);

        // group columns header
        $g->set_group_header( array(
                "useColSpanStyle"=>true,
                "groupHeaders"=>array(
                    array(
                        "startColumnName"=>'Payment_ID', // group starts from this column
                        "numberOfColumns"=>10, // group span to next 2 columns
                        "titleText"=>'Payment Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'File_Name', // group starts from this column
                        "numberOfColumns"=>2, // group span to next 2 columns
                        "titleText"=>'Image Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Company_ID', // group starts from this column
                        "numberOfColumns"=>6, // group span to next 2 columns
                        "titleText"=>'Company Information' // caption of group header
                    ),
                    array(
                        "startColumnName"=>'Address1', // group starts from this column
                        "numberOfColumns"=>8, // group span to next 2 columns
                        "titleText"=>"Company's Address" // caption of group header
                    )
                )
            )
        );

        // render grid and get html/js output
        $out = $g->render("payments");

        $this->render('index',array(
            'out'=>$out,
        ));
	}
示例#7
0
    /**
     * Delete document with rows in relative tables
     * @param $documentId
     */
    public static function deleteDocument($documentId) {
        $document = Documents::model()->findByPk($documentId);
        if ($document) {
            if ($document->Document_Type == self::W9) {
                $w9s = W9::model()->findAllByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                foreach ($w9s as $w9) {
                    W9::deleteW9($w9->W9_ID);
                }
            } else if ($document->Document_Type == self::AP) {
                $ap = Aps::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($ap) {
                    Aps::deleteAP($ap->AP_ID);
                }
            } else if ($document->Document_Type ==  self::PM) {
                $payment = Payments::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($payment) {
                    Payments::deletePayment($payment->Payment_ID);
                }
            } else if ($document->Document_Type == self::PO) {
                $po = Pos::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($po) {
                    Pos::deletePO($po->PO_ID);
                }
            } else if ($document->Document_Type == self::PC) {
                $pc = Pcs::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($pc) {
                    Pcs::deletePC($pc->PC_ID);
                }
            } else if ($document->Document_Type == self::AR) {
                $ar = Ars::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($ar) {
                    Ars::deleteAR($ar->AR_ID);
                }
            } else if ($document->Document_Type == self::PR) {
                $payroll = Payrolls::model()->findByAttributes(array(
                    'Document_ID' => $documentId,
                ));
                if ($payroll) {
                    Payrolls::deletePayroll($payroll->Payroll_ID);
                }
            }  else {
                $image = $document->image;
                $image->delete();
                $document->delete();

                // delete thumbnail
                $filePath = 'protected/data/thumbs/' . $documentId . '.jpg';
                if (file_exists($filePath)) {
                    @unlink($filePath);
                }

                // delete library links
                LibraryDocs::deleteDocumentLinks($documentId);
            }
        }
    }
示例#8
0
 public function actionGetpaymentsforzreport($id)
 {
     $zreport = ZReport::model()->findByPK($id);
     $result = Payments::model()->findAll("date=:date", array(":date" => $zreport->date));
     echo CJSON::encode($result);
 }
示例#9
0
    public function appendApsList ($client_id,$project_list,$doc_type){

        $condition = new CDbCriteria();
        $condition->condition =' documents.Client_ID = '.$client_id;
        $condition->addInCondition('documents.Project_ID ',$project_list);
        $condition->join = 'left join documents on documents.Document_ID = t.Document_ID';

        $models = Aps::model()->with('document')->findAll($condition);


        $xml_doc = $this->xml->createElement("document");
        if($models) {
            foreach ($models as $model) {
                $xml_row = $this->xml->createElement("row");

                foreach ($model->attributes as $key => $value) {
                    $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', $key);
                    $xml_row->appendChild($xml_field);
                }

                    //+ we need to insert several columns from document model
                    $xml_field = $this->xml->createElement("field",htmlentities($model->document->Origin,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', 'DocumentsOrigin');
                    $xml_row->appendChild($xml_field);
                    $xml_field = $this->xml->createElement("field",htmlentities($model->document->Created,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', 'DocumentsCreated');
                    $xml_row->appendChild($xml_field);
                    $xml_field = $this->xml->createElement("field",htmlentities($model->document->Project_ID,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', 'DocumentsProject_ID');
                    $xml_row->appendChild($xml_field);
                    // end of block

                /*documents processing*/
                $xml_doc_row = $this->xml->createElement("documents");
                foreach ($model->document->attributes as $key => $value) {
                    $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                    $xml_field->setAttribute('name', $key);
                    $xml_doc_row->appendChild($xml_field);
                }
                /*end of documents processing*/


                /*bacups processing*/

                $bacup = Documents::model()->findByPk($model->AP_Backup_Document_ID);
                $xml_backup_row = $this->xml->createElement("backup");
                if ($bacup){
                    foreach ($bacup->attributes as $key => $value) {
                        $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                        $xml_field->setAttribute('name', $key);
                        $xml_backup_row->appendChild($xml_field);
                    }
                }
                /*end of bacups processing*/

                /*payments connected processing*/
                $payment = Payments::model()->findByPk($model->Payment_ID);
                $xml_payment_row = $this->xml->createElement("payments");
                if ($payment){
                    foreach ($payment->attributes as $key => $value) {
                        $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                        $xml_field->setAttribute('name', $key);
                        $xml_payment_row->appendChild($xml_field);
                    }
                }
                /*end of payments processing*/

                /*po connected processing*/
                $po = Pos::model()->findByPk($model->PO_ID);
                $xml_po_row = $this->xml->createElement("pos_connected");
                if ($po){
                    foreach ($po->attributes as $key => $value) {
                        $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                        $xml_field->setAttribute('name', $key);
                        $xml_po_row->appendChild($xml_field);
                    }
                }
                /*end of payments processing*/

                /*dists processing*/
                $xml_dists = $this->xml->createElement("gl_dist_detail");
                    foreach ($model->dists as $dist) {
                        $xml_dist_row = $this->xml->createElement("dist_row");

                        foreach ($dist as $key=>$value) {
                            $xml_field = $this->xml->createElement("field",htmlentities($value,ENT_QUOTES | 'ENT_XML1'));
                            $xml_field->setAttribute('name', $key);
                            $xml_dist_row->appendChild($xml_field);
                        }



                        $xml_dists->appendChild($xml_dist_row);
                    }

                /*end of dists processing*/


                /*images processing*/
                $xml_image_row = $this->xml->createElement("images");
                $xml_field = $this->xml->createElement("field",$model->document->image->Image_ID);
                $xml_field->setAttribute('name', 'Image_ID');
                $xml_image_row->appendChild($xml_field);


                $filename = FileModification::prepareFileForExport($model->document->image->Document_ID,$doc_type,$this->filepath);
                $xml_field = $this->xml->createElement("field",$filename);
                $xml_field->setAttribute('name', 'File_Name');
                $xml_image_row->appendChild($xml_field);
                    $xml_row->appendChild($xml_field);
                $xml_field = $this->xml->createElement("field",$model->document->image->Mime_Type);
                $xml_field->setAttribute('name', 'Mime_Type');
                $xml_image_row->appendChild($xml_field);
                    $xml_row->appendChild($xml_field);
                $xml_field = $this->xml->createElement("field",$model->document->image->Pages_Count);
                $xml_field->setAttribute('name', 'Pages_Count');
                $xml_image_row->appendChild($xml_field);
                    $xml_row->appendChild($xml_field);
                /*end of images processing*/

                $xml_row->appendChild($xml_dists);
                $xml_row->appendChild($xml_backup_row);
                $xml_row->appendChild($xml_payment_row);
                $xml_row->appendChild($xml_po_row);
                $xml_row->appendChild($xml_doc_row);
                $xml_row->appendChild($xml_image_row);
                $xml_doc->appendChild($xml_row);


            }



            $this->wrapper->appendChild($xml_doc);


        }
    }
示例#10
0
 public function actionIncome()
 {
     $paysystem = $this->_createPaymentSystemModel();
     if ($paysystem === null) {
         return;
     }
     $result = $paysystem->payModel->processRequest();
     if (!$_POST && Yii::app()->request->getParam('payment') == 'success') {
         Yii::app()->user->setFlash('success', tt('Payment successfully held', 'payment'));
         $this->redirect(array('/usercpanel/main/payments'));
         exit;
     }
     if (!$_POST && Yii::app()->request->getParam('payment') == 'fail') {
         Yii::app()->user->setFlash('error', tt('Payment is canceled', 'payment'));
         $this->redirect(array('/usercpanel/main/payments'));
         exit;
     }
     // Обрабатываем успешный платеж
     if ($result['result'] == 'success') {
         $payment = Payments::model()->findByPk($result['id']);
         if ($payment) {
             if ($payment->status != Payments::STATUS_PAYMENTCOMPLETE) {
                 $payment->complete();
             }
             $paysystem->payModel->echoSuccess();
             Yii::app()->user->setFlash('success', tt('Payment successfully held', 'payment'));
             $this->redirect(array('/usercpanel/main/payments'));
         }
     }
     // Обрабатываем pending платеж
     if ($result['result'] == 'pending') {
         $payment = Payments::model()->findByPk($result['id']);
         if ($payment) {
             if ($payment->status != Payments::STATUS_PENDING) {
                 $payment->status = Payments::STATUS_PENDING;
                 $payment->update('status');
             }
         }
     }
     // Обрабатываем неудачный платеж
     if ($result['result'] == 'fail') {
         // Если в ответе от платежки есть id платежа - ставим ему статус "Отменен"
         if ($result['id']) {
             $payment = Payments::model()->findByPk($result['id']);
             if ($payment) {
                 if ($payment->status == Payments::STATUS_WAITPAYMENT) {
                     $payment->status = Payments::STATUS_DECLINED;
                     $payment->update(array('status'));
                     $paysystem->payModel->echoDeclined();
                     Yii::app()->user->setFlash('error', tt('Payment is canceled', 'payment'));
                 }
                 $this->redirect(array('/usercpanel/main/payments'));
             }
         }
         Yii::app()->user->setFlash('error', tt('Payment is canceled', 'payment'));
         $this->redirect(array('/site/index'));
         /*$paysystem->payModel->echoError();
         
         			$this->render('message', array(
         				'message' => '',
         			));*/
     }
     $this->redirect(array('/usercpanel/main/payments'));
 }
示例#11
0
    /**
     * Delete Payment with rows in relative tables
     * @param $paymentId
     */
    public static function deletePayment($paymentId)
    {
        $payment = Payments::model()->with('document.image')->findByPk($paymentId);
        if ($payment) {
            $document = $payment->document;
            $image = $document->image;
            $image->delete();
            $document->delete();

            PaymentsInvoice::model()->deleteAllByAttributes(array(
                'Payment_ID' => $paymentId,
            ));

            ApPayments::model()->deleteAllByAttributes(array(
                'Payment_ID' => $paymentId,
            ));

            // delete thumbnail
            $filePath = 'protected/data/thumbs/' . $payment->Document_ID . '.jpg';
            if (file_exists($filePath)) {
                @unlink($filePath);
            }

            // delete library links
            LibraryDocs::deleteDocumentLinks($payment->Document_ID);

            $payment->delete();
        }
    }
示例#12
0
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if (Yii::app()->request->isPostRequest) {
         // we only allow deletion via POST request
         $model = $this->loadModel($id);
         $c = Payments::model()->countByAttributes();
         if (null == $c) {
             if ($model->delete()) {
                 $msg = 'Счёт #' . $model->id . ' для Заказа #' . $model->order_id . ' ' . $model->order->name . ' удалён';
                 Yii::app()->user->setFlash('success', $msg);
                 Yii::app()->logger->write($msg);
             }
         } else {
             $msg = 'Счёт #' . $model->id . ' для Заказа #' . $model->order_id . ' ' . $model->order->name . ' нельзя удалить. Есть платежи: ' . $c;
             Yii::app()->user->setFlash('notice', $msg);
             Yii::app()->logger->write($msg);
         }
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
         }
     } else {
         throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
     }
 }
示例#13
0
 public function actionCalendar()
 {
     //        $this->layout = "//layouts/calendar";
     Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/my-calendar.css");
     Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/my-calendar-resp.css");
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/jQuery/jquery-ui.min.js", CClientScript::POS_HEAD);
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/fullcalendar/fullcalendar.js", CClientScript::POS_END);
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/plugins/spin/spin.js", CClientScript::POS_END);
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/main.js", CClientScript::POS_END);
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/my-calendar.js", CClientScript::POS_END);
     $returnArray = array();
     $day = 60 * 60 * 24;
     $time = time();
     $from = Yii::app()->request->getParam('from', '');
     $to = Yii::app()->request->getParam('to', '');
     $criteria = new CDbCriteria();
     $criteria->addCondition('mstRequestUsers.user_id = ' . Yii::app()->user->getInfo());
     $criteria->addCondition('mstRequestUsers.archived = 0');
     //        $criteria->addCondition('booking_type > 0');
     if (!empty($from)) {
         $criteria->addCondition('bookingDate >= ' . $from);
     }
     if (!empty($to)) {
         $criteria->addCondition('bookingDate < ' . $to);
     }
     $criteria->with = array('mstRequestUsers');
     $modelArray = Requests::model()->findAll($criteria);
     $eventsArray = array();
     $requestsTempArray = array();
     foreach ($modelArray as $model) {
         if ($model->booking_type > 0) {
             $criteria = new CDbCriteria();
             $criteria->select = 'sum(amount) as amount';
             $criteria->addCondition('request_id = ' . $model->id);
             $criteria->addCondition('status = 1');
             $modelSum = Payments::model()->find($criteria);
             $moneyPaid = (int) $modelSum->amount;
             $eventsArray[] = array('id' => $model->id, 'creator' => $model->createdBy->firstName . ' ' . $model->createdBy->lastName, 'title' => ComponentString::showPart($model->map->name, 14), 'map' => ComponentString::showPart($model->map->name, 28), 'event_type' => $model->eventType->name, 'start_time' => date('H:i A', strtotime($model->start_time)), 'end_time' => date('H:i A', strtotime($model->end_time)), 'start' => $model->eventDate, 'dateName' => date('l, F d, Y', strtotime($model->eventDate)), 'allDay' => true, 'type' => $model->booking_type, 'daysTotal' => ceil((strtotime($model->eventDate) - strtotime($model->created_on)) / $day), 'daysLeft' => ceil((strtotime($model->eventDate) - $time) / $day), 'moneyPaid' => $moneyPaid, 'moneyTotal' => $model->amount);
         } else {
             $requestsTempArray[date('d-m-Y', strtotime($model->eventDate))][] = 1;
         }
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('
         (LOWER(calendarType.name) = "flag" AND t.created_by = ' . Yii::app()->user->getInfo() . ') OR
         (LOWER(calendarType.name) = "unavailable" AND t.created_by = ' . Yii::app()->user->getInfo() . ') OR
         (LOWER(calendarType.name) = "holiday")
     ');
     $criteria->addCondition('calendarType.status = 1');
     $criteria->addCondition('t.status = 1');
     $criteria->with = array('calendarType');
     $modelArray = Calendar::model()->findAll($criteria);
     $flagsArray = array();
     $holidaysArray = array();
     $unavailableArray = array();
     foreach ($modelArray as $model) {
         switch (strtolower($model->calendarType->name)) {
             case 'flag':
                 $flagsArray[] = array('id' => $model->id, 'title' => ComponentString::showPart($model->message, 30), 'start' => $model->calendar_date);
                 break;
             case 'holiday':
                 $holidaysArray[] = array('id' => $model->id, 'title' => $model->message, 'start' => $model->calendar_date);
                 break;
             case 'unavailable':
                 $unavailableArray[] = array('id' => $model->id, 'title' => $model->message, 'start' => $model->calendar_date);
                 break;
         }
     }
     $requestsArray = array();
     foreach ($requestsTempArray as $key => $request) {
         $requestsArray[$key] = count($request);
     }
     $returnArray['events'] = $eventsArray;
     $returnArray['flags'] = $flagsArray;
     $returnArray['requests'] = $requestsArray;
     $returnArray['holidays'] = $holidaysArray;
     $returnArray['unavailable'] = $unavailableArray;
     $json = json_encode($returnArray);
     Yii::app()->clientScript->registerScript('mapvar10', "var json='" . $json . "';", CClientScript::POS_HEAD);
     $this->render('calendar');
 }
示例#14
0
 public function processRequest()
 {
     $return['result'] = 'fail';
     $return['id'] = intval(getReq("custom", 0));
     $payment = NULL;
     if ($return['id']) {
         $payment = Payments::model()->findByPk($return['id']);
     }
     if (!$return['id'] || !$payment) {
         logs('paypal not find payment');
         return $return;
     }
     $get_magic_quotes_exists = false;
     if (function_exists('get_magic_quotes_gpc')) {
         $get_magic_quotes_exists = true;
     }
     $postdata = "";
     foreach ($_POST as $key => $value) {
         if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
             $value = urlencode(stripslashes($value));
         } else {
             $value = urlencode($value);
         }
         $postdata .= "&{$key}={$value}";
     }
     $sGatewayURL = $this->mode == Paysystem::MODE_TEST ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr';
     $postdata .= "cmd=_notify-validate";
     $curl = curl_init($sGatewayURL);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Connection: Close', 'User-Agent: ' . $this->email));
     $response = curl_exec($curl);
     curl_close($curl);
     if ($response != "VERIFIED") {
         logs("TRANSACTION_NOT_VERIFIED");
         logs($response);
         logs($_POST);
         return $return;
     }
     if (strtolower($_POST['receiver_email']) != $this->email) {
         logs("INVALID_RECEIVER");
         logs($_POST);
         return $return;
     }
     if ($_POST["txn_type"] != "web_accept") {
         logs("INVALID_TRANSACTION_TYPE");
         logs($_POST);
         return $return;
     }
     $payment_status = Yii::app()->request->getParam('payment_status');
     if ($payment_status == "Completed" || $payment_status == "Pending") {
         $return['result'] = 'success';
         //        } elseif($payment_status == "Pending") {
         //            $return['result'] = 'pending';
         //            $return['pending_reason'] = getReq('pending_reason');
     } else {
         $return['result'] = 'fail';
     }
     return $return;
 }
示例#15
0
 public function actionPayments()
 {
     Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . "/css/account-payments.css");
     Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . "/js/account-payments.js", CClientScript::POS_END);
     $criteria = new CDbCriteria();
     $criteria->addCondition('to_user = '******' OR created_by = ' . Yii::app()->user->getInfo());
     $criteria->addCondition('status = 1');
     $modelArray = Payments::model()->findAll($criteria);
     $this->render('payments', array('payments' => $modelArray));
 }