/** * Delete AP with rows in relative tables * @param $apId */ public static function deleteAP($apId) { $ap = Aps::model()->with('document.image')->findByPk($apId); if ($ap) { $document = $ap->document; $image = $document->image; $image->delete(); $document->delete(); ApPayments::model()->deleteAllByAttributes(array( 'AP_ID' => $apId, )); GlDistDetails::model()->deleteAllByAttributes(array( 'AP_ID' => $apId, )); // delete thumbnail $filePath = 'protected/data/thumbs/' . $ap->Document_ID . '.jpg'; if (file_exists($filePath)) { @unlink($filePath); } // delete library links LibraryDocs::deleteDocumentLinks($ap->Document_ID); $ap->delete(); } }
/** * Delete AR with rows in relative tables * @param $arID */ public static function deleteAR($arID) { $ar = Ars::model()->with('document.image')->findByPk($arID); if ($ar) { $document = $ar->document; $image = $document->image; $image->delete(); $document->delete(); // delete thumbnail $filePath = 'protected/data/thumbs/' . $ar->Document_ID . '.jpg'; if (file_exists($filePath)) { @unlink($filePath); } // delete library links LibraryDocs::deleteDocumentLinks($ar->Document_ID); $ar->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); } } }
/** * Delete W9 with rows in relative tables * @param $w9Id */ public static function deleteW9($w9Id) { $w9 = W9::model()->with('document.image')->findByPk($w9Id); if ($w9) { $document = $w9->document; $documentW9s = W9::model()->findAllByAttributes(array( 'Document_ID' => $document->Document_ID, )); if (count($documentW9s) <= 1) { $image = $document->image; if ($image) $image->delete(); $document->delete(); } // delete thumbnail $filePath = 'protected/data/thumbs/' . $w9->Document_ID . '.jpg'; if (file_exists($filePath)) { @unlink($filePath); } // delete library links LibraryDocs::deleteDocumentLinks($w9->Document_ID); $w9->delete(); } }
/** * 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(); } }
/** * Delete PO with rows in relative tables * @param $poId */ public static function deletePO($poId) { $po = Pos::model()->with('document.image')->findByPk($poId); if ($po) { $document = $po->document; $image = $document->image; $image->delete(); $document->delete(); PoDists::model()->deleteAllByAttributes(array( 'PO_ID' => $poId, )); PoDescDetail::model()->deleteAllByAttributes(array( 'PO_ID' => $poId, )); PoPmtsTraking::model()->deleteAllByAttributes(array( 'PO_ID' => $poId, )); // delete thumbnail $filePath = 'protected/data/thumbs/' . $po->Document_ID . '.jpg'; if (file_exists($filePath)) { @unlink($filePath); } // delete library links LibraryDocs::deleteDocumentLinks($po->Document_ID); $po->delete(); } }