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