GWM : Credit notes line items : GWM
This commit is contained in:
parent
90d452e69e
commit
bdf97a9edc
@ -15,6 +15,7 @@ use App\Models\Ipinvoice_model;
|
||||
use App\Models\Ipattachment_model;
|
||||
use App\Models\Zohobooks_api_model;
|
||||
use App\Models\CreditNoteModel;
|
||||
use App\Models\IpCreditNotesItemsModel;
|
||||
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
@ -36,6 +37,7 @@ class User extends BaseController
|
||||
protected $ipinvoice_model;
|
||||
protected $ipattachment_model;
|
||||
protected $CreditNoteModel;
|
||||
protected $CreditNotesItemsModel;
|
||||
protected $session;
|
||||
|
||||
/**
|
||||
@ -53,6 +55,7 @@ class User extends BaseController
|
||||
$this->ipinvoice_model = new Ipinvoice_model();
|
||||
$this->ipattachment_model = new Ipattachment_model();
|
||||
$this->CreditNoteModel = new CreditNoteModel();
|
||||
$this->CreditNotesItemsModel = new IpCreditNotesItemsModel();
|
||||
$this->session = session();
|
||||
helper('form'); //$this->load->library('form_validation');
|
||||
$this->isLoggedIn();
|
||||
@ -1382,13 +1385,14 @@ class User extends BaseController
|
||||
|
||||
$tokenWithCreditNoteScope = generateNewTokenForCreditNoteScope();
|
||||
$cteditNotesRes = getAllCreditNotes($date_today, $date_yesterday, $tokenWithCreditNoteScope);
|
||||
$cteditNotesData = json_decode($cteditNotesRes['data'],true);
|
||||
|
||||
$cteditNotesData = json_decode($cteditNotesRes['data'],true);
|
||||
|
||||
if(count($cteditNotesData['creditnotes']))
|
||||
{
|
||||
$this->saveOrUpdateCreditNote($cteditNotesData['creditnotes']);
|
||||
$this->saveOrUpdateCreditNote($cteditNotesData['creditnotes'] , $tokenWithCreditNoteScope);
|
||||
}
|
||||
|
||||
// dd($cteditNotesData);
|
||||
|
||||
|
||||
foreach ($inv_array as $inv) {
|
||||
@ -1714,7 +1718,7 @@ class User extends BaseController
|
||||
}
|
||||
// END zoho API
|
||||
|
||||
public function saveOrUpdateCreditNote($data)
|
||||
public function saveOrUpdateCreditNote($data , $tokenWithCreditNoteScope )
|
||||
{
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
@ -1730,6 +1734,36 @@ class User extends BaseController
|
||||
$this->CreditNoteModel->insert($value);
|
||||
|
||||
}
|
||||
|
||||
//credit note line item api call
|
||||
$cteditNotesLineItemsRes = getCreditNotesItemDetails($value['creditnote_id'], $tokenWithCreditNoteScope);
|
||||
|
||||
$lineItemData = json_decode($cteditNotesLineItemsRes['data'],true);
|
||||
|
||||
if(count($lineItemData['creditnote']['line_items']))
|
||||
{
|
||||
foreach ($lineItemData['creditnote']['line_items'] as $itemkey => $itemvalue)
|
||||
{
|
||||
$itemvalue['creditnote_id'] = $value['creditnote_id'];
|
||||
|
||||
|
||||
|
||||
$existingCreditNoteItems = $this->CreditNotesItemsModel->where('line_item_id', $itemvalue['line_item_id'])->first();
|
||||
|
||||
if ($existingCreditNoteItems) {
|
||||
// Update existing record
|
||||
$this->CreditNotesItemsModel->update($itemvalue['line_item_id'], $itemvalue);
|
||||
|
||||
} else {
|
||||
// Insert new record
|
||||
$this->CreditNotesItemsModel->insert($itemvalue);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -185,6 +185,58 @@ if (! function_exists('getAllCreditNotes')) {
|
||||
'headers_new' => $headers,
|
||||
'data' => $result
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (! function_exists('getCreditNotesItemDetails')) {
|
||||
function getCreditNotesItemDetails($creditNoteId, $accesstoken)
|
||||
{
|
||||
// Initialize cURL
|
||||
$ch = curl_init();
|
||||
|
||||
// Zoho API credentials
|
||||
$organization_id = '776847408';
|
||||
$url_org = "https://www.zohoapis.com/books/v3/creditnotes/".$creditNoteId."?organization_id=$organization_id";
|
||||
|
||||
|
||||
// Set headers
|
||||
$headers = array(
|
||||
'Authorization: Zoho-oauthtoken ' . $accesstoken,
|
||||
// 'Content-Type: application/json'
|
||||
);
|
||||
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_URL, $url_org );
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
// Execute cURL request
|
||||
$result = curl_exec($ch);
|
||||
|
||||
// Check for errors
|
||||
if ($result === false) {
|
||||
return ['error' => curl_error($ch)];
|
||||
}
|
||||
|
||||
// Close cURL session
|
||||
curl_close($ch);
|
||||
|
||||
return [
|
||||
'headers_new' => $headers,
|
||||
'data' => $result
|
||||
];
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -47,14 +47,25 @@ class CreditNoteModel extends Model
|
||||
/**
|
||||
* Fetch all credit notes
|
||||
*/
|
||||
public function getAllCreditNotes($fromDate,$toDate)
|
||||
// public function getAllCreditNotes($fromDate,$toDate)
|
||||
// {
|
||||
// return $this->where('date >=', $fromDate )
|
||||
// ->where('date <=', $toDate )
|
||||
// ->orderBy('date', 'DESC')
|
||||
// ->findAll();
|
||||
// }
|
||||
|
||||
public function getAllCreditNotes($fromDate, $toDate)
|
||||
{
|
||||
return $this->where('date >=', $fromDate )
|
||||
->where('date <=', $toDate )
|
||||
->orderBy('date', 'DESC')
|
||||
return $this->select('ip_credit_notes.*, ip_credit_notes_items.name as item_name')
|
||||
->join('ip_credit_notes_items', 'ip_credit_notes.creditnote_id = ip_credit_notes_items.creditnote_id', 'left')
|
||||
->where('ip_credit_notes.date >=', $fromDate)
|
||||
->where('ip_credit_notes.date <=', $toDate)
|
||||
->orderBy('ip_credit_notes.date', 'DESC')
|
||||
->findAll();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetch a single credit note by ID
|
||||
*/
|
||||
|
||||
71
app/Models/IpCreditNotesItemsModel.php
Normal file
71
app/Models/IpCreditNotesItemsModel.php
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class IpCreditNotesItemsModel extends Model
|
||||
{
|
||||
protected $table = 'ip_credit_notes_items';
|
||||
protected $primaryKey = 'line_item_id';
|
||||
protected $useAutoIncrement = false;
|
||||
|
||||
protected $allowedFields = [
|
||||
'line_item_id',
|
||||
'item_id',
|
||||
'creditnote_id',
|
||||
'sku',
|
||||
'account_id',
|
||||
'account_name',
|
||||
'name',
|
||||
'internal_name',
|
||||
'description',
|
||||
'item_order',
|
||||
'invoice_id',
|
||||
'invoice_item_id',
|
||||
'quantity',
|
||||
'pricing_scheme',
|
||||
'unit',
|
||||
'project_id',
|
||||
'pricebook_id',
|
||||
'discount_amount',
|
||||
'discount',
|
||||
'discount_account_id',
|
||||
'discount_account_name',
|
||||
'bcy_rate',
|
||||
'rate',
|
||||
'sales_margin',
|
||||
'tax_id',
|
||||
'tax_name',
|
||||
'tax_type',
|
||||
'tax_percentage',
|
||||
'tds_tax_id',
|
||||
'tds_tax_name',
|
||||
'tds_tax_percentage',
|
||||
'tds_tax_amount',
|
||||
'reverse_charge_tax_id',
|
||||
'gst_treatment_code',
|
||||
'item_total',
|
||||
'product_type',
|
||||
'item_type',
|
||||
'has_product_type_mismatch',
|
||||
'has_invalid_hsn',
|
||||
'hsn_or_sac',
|
||||
'image_document_id',
|
||||
'is_credit_only_item',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
protected $useTimestamps = true;
|
||||
protected $createdField = 'created_at';
|
||||
protected $updatedField = 'updated_at';
|
||||
|
||||
/**
|
||||
* Get items by credit note ID
|
||||
*/
|
||||
public function getItemsByCreditNoteId($creditnoteId)
|
||||
{
|
||||
return $this->where('creditnote_id', $creditnoteId)->findAll();
|
||||
}
|
||||
}
|
||||
@ -238,6 +238,7 @@
|
||||
<th>Credit Note</th>
|
||||
<th>Invoice</th>
|
||||
<th>Client </th>
|
||||
<th>Item Name</th>
|
||||
<th>Item Price</th>
|
||||
<th>Item qty</th>
|
||||
<th>Sub Total</th>
|
||||
@ -257,6 +258,7 @@
|
||||
<td><?php echo $val['creditnote_number'] ?></td>
|
||||
<td><?php echo $val['applied_invoices'] ?></td>
|
||||
<td><?php echo $val['customer_name'] ?></td>
|
||||
<td><?php echo $val['item_name'] ?></td>
|
||||
<td><?php echo $val['item_price'] ?></td>
|
||||
<td><?php echo $val['item_quantity'] ?></td>
|
||||
<td><?php echo $val['item_total_without_tax'] ?></td>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user