/** * 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); } }
/** * Delete Payroll with rows in relative tables * @param $payrollID */ public static function deletePayroll($payrollID) { $payroll = Payrolls::model()->with('document.image')->findByPk($payrollID); if ($payroll) { $document = $payroll->document; $image = $document->image; $image->delete(); $document->delete(); // delete thumbnail $filePath = 'protected/data/thumbs/' . $payroll->Document_ID . '.jpg'; if (file_exists($filePath)) { @unlink($filePath); } // delete library links LibraryDocs::deleteDocumentLinks($payroll->Document_ID); $payroll->delete(); } }
/** * 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); } } }
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); } }