FIX_new button For Subscription : ps
This commit is contained in:
parent
8c11a3cdf4
commit
4148d76e2c
@ -119,6 +119,7 @@ $routes->get("new_book_invoice/(:any)", "Invoice::new_book_invoice/$1");
|
||||
$routes->get("new_subscription_invoice/(:any)", "Invoice::new_subscription_invoice/$1");
|
||||
// $routes->get("download_invoice_pdf/(:num)",'Invoice::download_invoice_pdf/$1');
|
||||
$routes->get("download_invoice_pdf/(:any)", 'Invoice::download_invoice_pdf/$1');
|
||||
$routes->post('update_approval_subscription', 'Invoice::update_approval_subscription');
|
||||
|
||||
|
||||
$routes->post("saveBook", "Invoice::saveBook");
|
||||
|
||||
@ -1149,4 +1149,131 @@ class Invoice extends BaseController
|
||||
// Return the response as JSON
|
||||
return $this->response->setJSON($response);
|
||||
}
|
||||
|
||||
## update approval subscription details of the invoice
|
||||
public function update_approval_subscription()
|
||||
{
|
||||
$response = [];
|
||||
## Declarions
|
||||
helper(['session', 'financial_year_helper']);
|
||||
try{
|
||||
// Initialize models and variables
|
||||
$model = new InvoiceModel();
|
||||
$invdate = $this->request->getVar('invoice_date');
|
||||
$invoice_status = $this->request->getPost('status');
|
||||
$invoice_id = $this->request->getPost('invoice_id');
|
||||
$customer_id = (int)$this->request->getPost('customer_name');
|
||||
$requestData = $this->request->getPost();
|
||||
$invdate_dbformat = !empty($invdate) ? \DateTime::createFromFormat('d/m/Y', $invdate)->format('Y-m-d') : null;
|
||||
|
||||
$invoice_data = [
|
||||
'invoice_number' => $requestData['invoice_number'],
|
||||
'invoice_type' => $requestData['invoice_type'],
|
||||
'customer_id' => $customer_id,
|
||||
'billing_address_id' => (int)$requestData['billing_address_id'],
|
||||
'billing_address' => $requestData['billing_address'],
|
||||
'shipping_address_id' => (int)$requestData['shipping_address_id'],
|
||||
'shipping_address' => $requestData['shipping_address'],
|
||||
'notes' => $requestData['notes'],
|
||||
'invoice_date' => $invdate_dbformat,
|
||||
'subtotal' => (float)$requestData['sub_total'],
|
||||
'tax' => (float)$requestData['invoice_tax'],
|
||||
'dis_type' => isset($requestData['dis_type'])?$requestData['dis_type']:NULL,
|
||||
'discount' => (float)$requestData['discount'],
|
||||
'exact_total_amount' => (float)$requestData['exact_total_amount'],
|
||||
'total_amount' => (int)$requestData['grand_total'],
|
||||
'payment_note' => $requestData['payment_note'],
|
||||
'event_id' => (int)$requestData['event_id'],
|
||||
'business_id' => (int)get_business_id(),
|
||||
'invoice_id' => $invoice_id,
|
||||
'updated_by' => (int)get_logged_user_id()
|
||||
];
|
||||
$invoice_where = ['customer_id' => $customer_id, 'invoice_id' => $invoice_id];
|
||||
$invoice_aff_row = $model->updateData('invoice', $invoice_data, $invoice_where);
|
||||
|
||||
|
||||
if ($invoice_aff_row) {
|
||||
$response['invoice']['message'] = 'Subscription Master (Invoice) Changes Updated successfully';
|
||||
$this->logger->info("Update Approval Subscription Master (Invoice) has been updated successfully. Updated ID = " . $invoice_id);
|
||||
} else {
|
||||
$response['invoice']['message'] = 'Subscription Master (Invoice) There Is No Changes to Updated';
|
||||
$this->logger->error("Update Approval Subscription Master (Invoice) Err Failed to update ID =" . $invoice_id);
|
||||
}
|
||||
|
||||
## Invoice Line Item..
|
||||
$invoice_child_id = $requestData['invoice_child_id'];
|
||||
$count = count($invoice_child_id);
|
||||
if ($count > 0) {
|
||||
for ($x = 0; $x < $count; $x++) {
|
||||
if (!empty($requestData['item_details'][$x])) {
|
||||
$invoiceitem_arr[$x]['invoice_id'] = $invoice_id;
|
||||
$invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
|
||||
$invoiceitem_arr[$x]['description'] = $requestData['description'][$x];
|
||||
$invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
|
||||
$invoiceitem_arr[$x]['tax'] = (float)$requestData['tax'][$x];
|
||||
$invoiceitem_arr[$x]['unit_price'] = (float)$requestData['rate'][$x];
|
||||
$invoiceitem_arr[$x]['subtotal'] = (float)$requestData['amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_amount'] = (float)$requestData['discount_amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_type'] = $requestData['discount_type'][$x];
|
||||
if (!empty($requestData['from_subscription'])) {
|
||||
$invoiceitem_arr[0]['from_subscription'] = \DateTime::createFromFormat('d/m/Y', $requestData['from_subscription'])->format('Y-m-d');
|
||||
}
|
||||
|
||||
if (!empty($requestData['to_subscription'])) {
|
||||
$invoiceitem_arr[0]['to_subscription'] = \DateTime::createFromFormat('d/m/Y', $requestData['to_subscription'])->format('Y-m-d');
|
||||
}
|
||||
$invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['invoice_child_id'] = $invoice_child_id[$x];
|
||||
}
|
||||
}
|
||||
$statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
|
||||
$response['item']['message'] = 'Subscription Item (Invoice Item)'.implode( ',' , $statement);
|
||||
$this->logger->error("Update Approval Subscription Child (1st Child) =" .implode( ',' , $statement));
|
||||
## Subscription..
|
||||
for ($x = 0; $x < $count; $x++) {
|
||||
$product_id =(int)$requestData['item_details'][$x];
|
||||
$from_sub_date = \DateTime::createFromFormat('d/m/Y', $requestData['from_subscription'])->format('Y-m-d');
|
||||
$to_sub_date = \DateTime::createFromFormat('d/m/Y', $requestData['to_subscription'])->format('Y-m-d');
|
||||
|
||||
$subscription_data = [
|
||||
'customer_id' => $customer_id,
|
||||
'invoice_id' => $invoice_id,
|
||||
'scheme_id' => $product_id,
|
||||
'from_subscription' => $from_sub_date,
|
||||
'to_subscription' => $to_sub_date,
|
||||
'business_id' => (int)get_business_id(),
|
||||
'updated_by' => (int)get_logged_user_id()
|
||||
];
|
||||
|
||||
$subscription_where = [
|
||||
'customer_id' => $customer_id,
|
||||
'invoice_id' => $invoice_id,
|
||||
'scheme_id' => $product_id
|
||||
];
|
||||
}
|
||||
$subs_aff_row = $model->updateData('subscription', $subscription_data, $subscription_where);
|
||||
if ($subs_aff_row) {
|
||||
$response['subscription']['message'] = 'Subscription has been updated successfully.';
|
||||
$this->logger->info("Subscription updated successfully. ID = $invoice_id");
|
||||
} else {
|
||||
$response['subscription']['message'] = 'Subscription update failed. Please try again.';
|
||||
$this->logger->error("Failed to update subscription. ID = $invoice_id");
|
||||
}
|
||||
}else{
|
||||
$response['item']['message'] = 'Subscription Item (Invoice Item) There Is No Changes to Updated';
|
||||
$response['subscription']['message'] = 'Subscription There Is No Changes to Updated';
|
||||
}
|
||||
$response['success'] = true;
|
||||
$response['message'] = "Successfully Updation";
|
||||
} catch (\Exception $e) {
|
||||
$response['success'] = false;
|
||||
$response['message'] = 'Error: ' . $e->getMessage();
|
||||
$this->logger->error("Error updating subscription: " . $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->response->setJSON($response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ class SubscriptionModel extends Model
|
||||
{
|
||||
protected $table = 'subscription';
|
||||
protected $primaryKey = 'sub_id';
|
||||
protected $allowedFields = ['sub_id','scheme_id','customer_id','to_subscription','from_subscription','mode','created_on','created_by','business_id'];
|
||||
protected $allowedFields = ['sub_id','scheme_id','customer_id','to_subscription','from_subscription','mode','created_on','created_by','updated_by','updated_on','business_id'];
|
||||
|
||||
|
||||
|
||||
|
||||
@ -288,7 +288,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<!-- <textarea name="description[]" class="form-control" placeholder="Enter Description" id="<?= "description" . $inx; ?>" cols="26" rows="2" style="margin-top: 16px;border-color: lightgray;width:247px;"><?= isset($ii_details['description']) ? $ii_details['description'] : '' ?></textarea> -->
|
||||
<span> </span>
|
||||
<textarea name="description[]" class="form-control" placeholder="Enter Description" id="<?="description".$inx;?>" rows="2" style="border: 1px dashed #ddd"><?= isset($ii_details['description']) ? $ii_details['description'] : '' ?></textarea>
|
||||
<input type="hidden" class="form-control" id="<?= "hiddenInvoiceChildId" . $inx; ?>" name="invoice_child_id[]" value="" placeholder="hidden for invoice child/item id" value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" />
|
||||
<input type="hidden" class="form-control" id="<?= "hiddenInvoiceChildId" . $inx; ?>" name="invoice_child_id[]" placeholder="hidden for invoice child/item id" value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" />
|
||||
</td>
|
||||
<td style="width:8%;"><input type="number" class="form-control item-quantity" id="<?="quantity".$inx;?>" name="quantity[]" oninput="calculateInvoice(this,<?= $inx; ?>)" value="<?= isset($ii_details['quantity']) ? $ii_details['quantity'] : '' ?>" min="1" />
|
||||
</td>
|
||||
@ -334,7 +334,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<!-- <textarea name="description[]" class="form-control" placeholder="Enter Description" id="" cols="26" rows="2" style="margin-top: 16px;border-color: lightgray;width:247px;"></textarea> -->
|
||||
<span> </span>
|
||||
<textarea name="description[]" class="form-control" placeholder="Enter Description" id="description0" rows="2" style="border: 1px dashed #ddd"></textarea>
|
||||
<input type="hidden" class="form-control" id="hiddenInvoiceChildId0" name="invoice_child_id[]" value="" placeholder="hidden for invoice child/item id" />
|
||||
<input type="hidden" class="form-control" id="hiddenInvoiceChildId0" name="invoice_child_id[]" placeholder="hidden for invoice child/item id" />
|
||||
|
||||
</td>
|
||||
|
||||
@ -645,6 +645,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
<div class="form-group m-b-0">
|
||||
<button type="submit" class="btn btn-white waves-effect waves-light" name="saveas" value="Draft" id="saveDraftButton">Save as Draft</button>
|
||||
<button type="button" class="btn btn-primary waves-effect" name="saveas" value="Approved" id="saveApprovedButton">Save as Approved</button>
|
||||
<button type="button" class="btn btn-white waves-effect waves-light" name="save" value="Save" id="saveButton">Save</button>
|
||||
<button type="button" class="btn btn-white waves-effect waves-light" name="void" value="Void" id="voidButton">Void</button>
|
||||
<button type="button" class="btn btn-white waves-effect" name="cancel" value="Cancel" id="cancelButton">Cancel</button>
|
||||
</div>
|
||||
@ -873,7 +874,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
$('#saveDraftButton').click(function() {
|
||||
console.log('Save as Draft button clicked');
|
||||
});
|
||||
|
||||
|
||||
$('#voidButton').click(function() {
|
||||
console.log('Void button clicked');
|
||||
});
|
||||
@ -884,7 +885,7 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
});
|
||||
|
||||
function hideAllButtons() {
|
||||
$('#cancelButton, #saveDraftButton, #voidButton, #saveApprovedButton').hide();
|
||||
$('#cancelButton, #saveDraftButton, #voidButton, #saveApprovedButton, #saveButton').hide();
|
||||
}
|
||||
|
||||
// Function to show buttons based on status and invoice_type
|
||||
@ -893,14 +894,14 @@ if (isset($invoice_item_details[0]['to_subscription']) && !empty($invoice_item_d
|
||||
if (invoice_type == '1' || invoice_type =='2') {
|
||||
if (status == '') {
|
||||
$('#saveDraftButton, #saveApprovedButton').show();
|
||||
} else if (status === 'Draft') {
|
||||
} else if (status == 'Draft') {
|
||||
$('#voidButton, #saveDraftButton, #saveApprovedButton').show();
|
||||
} else if (status === 'Approved') {
|
||||
} else if (status == 'Approved') {
|
||||
$('#cancelButton').show();
|
||||
if (invoice_type === '2') {
|
||||
$('#saveApprovedButton').show();
|
||||
if (invoice_type == '2') {
|
||||
$('#saveButton').show();
|
||||
}
|
||||
} else if (status === 'Cancelled' || status === 'Void') {
|
||||
} else if (status == 'Cancelled' || status == 'Void') {
|
||||
hideAllButtons();
|
||||
}
|
||||
}
|
||||
@ -1991,6 +1992,30 @@ function saveInvoiceCustomer() {
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
$('#saveButton').click(function() {
|
||||
var formData = $("#myForm").serialize();
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
data: formData, // Passing serialized form data
|
||||
dataType: 'json',
|
||||
url: '<?php echo base_url("update_approval_subscription"); ?>',
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
alert(response.message);
|
||||
console.log(response);
|
||||
setTimeout(function(){ window.location.href = '" . base_url("subscribers_list") . "'; }, 250);
|
||||
} else {
|
||||
alert(response.message);
|
||||
console.log(response); // Logging the response from backend
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error(error); // Logging any errors
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
@ -51,27 +51,34 @@
|
||||
$invoice_date = date('d/m/Y', strtotime($row['invoice_date']));
|
||||
$from_date = date('d/m/Y', strtotime($row['from_subscription']));
|
||||
$to_date = date('d/m/Y', strtotime($row['to_subscription']));
|
||||
$daysRemaining = (int)$row['subscription_in_days'];
|
||||
$fromDateTime = (new DateTime($row['from_subscription']))->format('Y-m-d');
|
||||
$toDateTime = (new DateTime($row['to_subscription']))->format('Y-m-d');
|
||||
$currentDate = (new DateTime())->format('Y-m-d');
|
||||
if ($currentDate === $toDateTime) {
|
||||
$class = 'text-danger';
|
||||
$message = "Expired on Today";
|
||||
} elseif ($currentDate > $toDateTime) {
|
||||
// $daysRemaining = (int)$row['subscription_in_days'];
|
||||
// $fromDateTime = (new DateTime($row['from_subscription']))->format('Y-m-d');
|
||||
// $toDateTime = (new DateTime($row['to_subscription']))->format('Y-m-d');
|
||||
// $currentDate = (new DateTime())->format('Y-m-d');
|
||||
$fromDateTime = new DateTime($row['from_subscription']);
|
||||
$toDateTime = new DateTime($row['to_subscription']);
|
||||
$currentDate = new DateTime();
|
||||
|
||||
// Calculate days remaining
|
||||
$interval = $currentDate->diff($toDateTime);
|
||||
$daysRemaining = $interval->days;
|
||||
|
||||
// Adjust class and message based on remaining days
|
||||
if ($currentDate > $toDateTime) {
|
||||
$class = 'text-danger';
|
||||
$message = "Expired";
|
||||
} elseif ($currentDate == $toDateTime) {
|
||||
$class = 'text-danger';
|
||||
$message = "Expired on Today";
|
||||
} elseif ($daysRemaining == 1) {
|
||||
$class = 'text-warning';
|
||||
$message = "Expires in 1 day";
|
||||
} elseif ($daysRemaining <= 7) {
|
||||
$class = 'text-warning';
|
||||
$message = "Expires in $daysRemaining days";
|
||||
} else {
|
||||
if ($daysRemaining == 1) {
|
||||
$class = 'text-warning';
|
||||
$message = "Expires in 1 day";
|
||||
} elseif ($daysRemaining <= 7) {
|
||||
$class = 'text-warning';
|
||||
$message = "Expires in $daysRemaining days";
|
||||
} else {
|
||||
$class = 'text-success';
|
||||
$message = "$daysRemaining days until expiration";
|
||||
}
|
||||
$class = 'text-success';
|
||||
$message = "$daysRemaining days until expiration";
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user