Ejemplo n.º 1
0
    public function appendGeneralDocList ($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';

        if ($doc_type=='PC') {
            $models = Pcs::model()->with('document')->findAll($condition);
        } else if ($doc_type=='W9') {
            $models = W9::model()->with('document')->findAll($condition);
        } else if ($doc_type=='JE') {
            $models = Journals::model()->with('document')->findAll($condition);
        } else if ($doc_type=='AR') {
            $models = Ars::model()->with('document')->findAll($condition);
        } else if ($doc_type=='PR') {
            $models = Payrolls::model()->with('document')->findAll($condition);
        } else if ($doc_type=='GF') {
            //$models = G::model()->findAll($condition);
        } else if ($doc_type=='PM') {
            $models = Payments::model()->with('document')->findAll($condition);
        } else if ($doc_type=='PC') {
            $models = Ars::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

                $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);
                }

                /**/
                $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);
                                /**/

                $xml_row->appendChild($xml_doc_row);
                $xml_row->appendChild($xml_image_row);
                $xml_doc->appendChild($xml_row);


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

        }
    }
Ejemplo n.º 2
0
    /**
     * Add document to folder
     * @param $docId
     * @param null $vendorID
     */
    public static function addDocumentToFolder($docId, $vendorID = null)
    {
        $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::createVendorFolder($document->Project_ID, $payment->Vendor_ID, $year);
            } elseif ($document->Document_Type == Documents::AP) {
                $ap = Aps::model()->findByAttributes(array(
                    'Document_ID' => $docId,
                ));

                $year = substr($ap->Invoice_Date, 0, 4);

                $subsectionId = Sections::createVendorFolder($document->Project_ID, $ap->Vendor_ID, $year);
                if ($ap->AP_Backup_Document_ID != 0) {
                    $bu = LibraryDocs::model()->findByAttributes(array(
                        'Document_ID' => $ap->AP_Backup_Document_ID,
                        'Subsection_ID' => $subsectionId,
                    ));

                    if (!$bu) {
                        $libDoc = new LibraryDocs();
                        $libDoc->Document_ID = $ap->AP_Backup_Document_ID;
                        $libDoc->Subsection_ID = $subsectionId;
                        $libDoc->Access_Type = Storages::HAS_ACCESS;
                        $libDoc->Sort_Numb = 0;
                        if ($libDoc->validate()) {
                            $libDoc->save();
                        }
                    }
                }
            } elseif ($document->Document_Type == Documents::PO) {
                $po = Pos::model()->findByAttributes(array(
                    'Document_ID' => $docId,
                ));

                $year = substr($po->PO_Date, 0, 4);

                $subsectionId = Sections::createVendorFolder($document->Project_ID, $po->Vendor_ID, $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();
                        }
                    }
                }
            } elseif ($document->Document_Type == Documents::BU) {
                //get po or ap date
                $ap = Aps::model()->findByAttributes(array(
                    'AP_Backup_Document_ID' => $docId,
                ));
                if ($ap) {
                    $year = substr($ap->Invoice_Date, 0, 4);
                } else {
                    $po = Pos::model()->findByAttributes(array(
                        'PO_Backup_Document_ID' => $docId,
                    ));
                    if ($po) {
                        $year = substr($po->PO_Date, 0, 4);
                    }
                }
                $subsectionId = Sections::createVendorFolder($document->Project_ID, $vendorID, $year);
            } elseif ($document->Document_Type == Documents::PR) {
                $payroll = Payrolls::model()->findByAttributes(array(
                    'Document_ID' => $document->Document_ID,
                ));

                $year = substr($payroll->Week_Ending, 0, 4);

                $subsectionId = Sections::createPayrollFolder($document->Project_ID, $year, $payroll->Week_Ending);
            } elseif ($document->Document_Type == Documents::JE) {
                $je = Journals::model()->findByAttributes(array(
                    'Document_ID' => $document->Document_ID,
                ));

                $subsectionId = Sections::createJournalEntryFolder($document->Project_ID, $je->JE_Date);
            } elseif ($document->Document_Type == Documents::PC) {
                $pc = Pcs::model()->findByAttributes(array(
                    'Document_ID' => $document->Document_ID,
                ));

                $year = substr($pc->Envelope_Date, 0, 4);

                $subsectionId = Sections::createPettyCashFolder($document->Project_ID, $year, $pc->Employee_Name);
            } elseif ($document->Document_Type == Documents::AR) {
                $ar = Ars::model()->findByAttributes(array(
                    'Document_ID' => $document->Document_ID,
                ));

                $year = substr($ar->Invoice_Date, 0, 4);

                $subsectionId = Sections::createAccountsReceivableFolder($document->Project_ID, $year, $ar->Invoice_Date);
            }

            $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);
        }
    }
Ejemplo n.º 3
0
    /**
     * Find JEs to entry data
     */
    public static function findJEsToEntry()
    {
        $queryString = $_SESSION['last_je_to_entry_search']['query'];
        $options =  $_SESSION['last_je_to_entry_search']['options'];

        $condition = new CDbCriteria();
        $condition->join = "right JOIN documents ON documents.Document_ID=t.Document_ID";
        $condition->condition = "t.JE_Number = '0'";

        $countCond = 0;
        if (count($options) > 0 && trim($queryString) != '') {
            $search_condition = new CDbCriteria();

            if ($options['search_option_jdate']) {
                $search_condition->compare('t.JE_Date', $queryString, true, 'OR');
                $countCond++;
            }

            if ($options['search_option_jnumber']) {
                $search_condition->compare('t.JE_Number', $queryString, true, 'OR');
                $countCond++;
            }

            if ($options['search_option_transaction_num']) {
                $search_condition->compare('t.JE_Transaction_ID', $queryString, true, 'OR');
                $countCond++;
            }

            if ($options['search_option_desc']) {
                $search_condition->compare('t.JE_Desc', $queryString, true, 'OR');
                $countCond++;
            }
        }






        if (Yii::app()->user->userType == UsersClientList::PROCESSOR || Yii::app()->user->userType == UsersClientList::APPROVER
            || Yii::app()->user->userType == UsersClientList::CLIENT_ADMIN) {
            $condition->addCondition("documents.Client_ID='" . Yii::app()->user->clientID . "'");
        }

        if (Yii::app()->user->userType == UsersClientList::PROCESSOR || ((Yii::app()->user->userType == UsersClientList::APPROVER
            || Yii::app()->user->userType == UsersClientList::CLIENT_ADMIN) && is_numeric(Yii::app()->user->projectID))) {
            $condition->addCondition("documents.Project_ID='" . Yii::app()->user->projectID . "'");
        }
        if (Yii::app()->user->userType == UsersClientList::USER
            && is_numeric(Yii::app()->user->projectID)) {
            $condition->addCondition("documents.Project_ID='" . Yii::app()->user->projectID . "'");
            $condition->addCondition("documents.User_ID='" . Yii::app()->user->userID . "'");
        }

        if (Yii::app()->user->userType == Users::DATA_ENTRY_CLERK) {
            //adding condition to allow DEC see only documents of clients that he has access
            $cli_array = Clients::getClientsIDList(Yii::app()->user->userID);
            $condition->addInCondition('documents.Client_ID', $cli_array);
        }

        $condition->order = "documents.Created ASC";

        if( $countCond > 0 ) $condition->mergeWith($search_condition);

        $jes = Journals::model()->findAll($condition);

        return $jes;
    }