daybook calculation updation : kdk
This commit is contained in:
parent
c561afd850
commit
3e9aae4c48
@ -152,6 +152,8 @@ class DayBook_Controller extends REST_Controller {
|
||||
$req['PaidTo'] = $reqData['paidTo'];
|
||||
$req['PaidDescription'] = $reqData['description_paid'];
|
||||
$req['VoucherNumber'] = $reqData['voucherNumber'];
|
||||
$req['BranchCode'] = $reqData['branch'];
|
||||
$req['Name'] = $reqData['name'];
|
||||
$date = date('Y-m-d H:i:s');
|
||||
$req['UpdatedOn'] = $date;
|
||||
$updatedayBookDetails = $this->daybook_model->update_dayBookDetails($req , $updateFor);// Check if the employee exist
|
||||
|
||||
@ -99,16 +99,54 @@ class DayBook_model extends CI_Model
|
||||
|
||||
// delete the daybook details
|
||||
public function delete_dayBookDetails($id) {
|
||||
|
||||
// echo $id;exit();
|
||||
|
||||
$mysql = "SELECT * FROM ".DAYBOOKMASTER." WHERE ID = '$id'";
|
||||
$deleteDetails = $this->db->query($mysql);
|
||||
$deleteDataDetails = $deleteDetails->result();
|
||||
$branch = $deleteDataDetails[0]->BranchCode;
|
||||
|
||||
$sql = "SELECT * FROM ".DAYBOOKMASTER." WHERE (BranchCode = '$branch' AND ID < '$id')
|
||||
ORDER BY ID DESC
|
||||
LIMIT 1 ";
|
||||
|
||||
$currBalance = 0;
|
||||
$latestUpdate = $this->db->query($sql);
|
||||
$latestUpdateDetails = $latestUpdate->result();
|
||||
$currBalance = $latestUpdateDetails[0]->Balance;
|
||||
$currID = $latestUpdateDetails[0]->ID;
|
||||
|
||||
$sql1 = " DELETE FROM ".DAYBOOKMASTER." WHERE ID ='$id'";
|
||||
// update branch to staff_branch table
|
||||
if ($this->db->query($sql1) == '1') {
|
||||
$result['deletedStatus'] = true;
|
||||
$result['message'] = "Entry is Deleted";
|
||||
} else {
|
||||
$result['deletedStatus'] = false;
|
||||
$result['message'] = "Something went wrong.please try again";
|
||||
}
|
||||
// update branch to staff_branch table
|
||||
if ($this->db->query($sql1) == '1') {
|
||||
|
||||
$sql2 = "SELECT * FROM ".DAYBOOKMASTER." WHERE (BranchCode = '$branch' AND ID > '$currID')
|
||||
ORDER BY ID ASC";
|
||||
$latestUpdate2 = $this->db->query($sql2);
|
||||
$latestUpdateDetails2 = $latestUpdate2->result();
|
||||
|
||||
foreach( $latestUpdateDetails2 as $clip){
|
||||
if($clip->Name == 'I002') {
|
||||
//Income
|
||||
$currBalance = $currBalance + $clip->Amount;
|
||||
}else if ($clip->Name == 'I001') {
|
||||
//Expense
|
||||
$currBalance = $currBalance - $clip->Amount;
|
||||
} else {
|
||||
}
|
||||
$updateSql = "UPDATE ".DAYBOOKMASTER." SET Balance ='$currBalance' WHERE ID = '$clip->ID'";
|
||||
$this->db->query($updateSql);
|
||||
}
|
||||
|
||||
$result['deletedStatus'] = true;
|
||||
$result['message'] = "Entry is Deleted";
|
||||
|
||||
} else {
|
||||
$result['deletedStatus'] = false;
|
||||
$result['message'] = "Something went wrong.please try again";
|
||||
}
|
||||
|
||||
// print_r($latestUpdateDetails);exit();
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -172,11 +210,55 @@ class DayBook_model extends CI_Model
|
||||
|
||||
// update existing daybook details
|
||||
public function update_dayBookDetails($Arr, $upFor) {
|
||||
|
||||
$branch = $Arr['BranchCode'];
|
||||
$sql = "SELECT * FROM ".DAYBOOKMASTER." WHERE (BranchCode = '$branch' AND ID < '$upFor')
|
||||
ORDER BY ID DESC
|
||||
LIMIT 1 ";
|
||||
$latestUpdate = $this->db->query($sql);
|
||||
$latestUpdateDetails = $latestUpdate->result();
|
||||
$prevBalance = $latestUpdateDetails[0]->Balance;
|
||||
|
||||
if($Arr['Name'] == 'I002') {
|
||||
//Income
|
||||
$Arr['Balance'] = $prevBalance + $Arr['Amount'];
|
||||
}else if ($Arr['Name'] == 'I001') {
|
||||
//Expense
|
||||
$Arr['Balance'] = $prevBalance - $Arr['Amount'];
|
||||
} else {
|
||||
$Arr['Balance'] = 0;
|
||||
}
|
||||
|
||||
$this->db->where('ID', $upFor);
|
||||
$this->db->update(DAYBOOKMASTER, $Arr);
|
||||
if ($this->db->affected_rows() == '1') {
|
||||
$result['updateDetailsStatus'] = true;
|
||||
$result['message'] = "Successfully Details Updated";
|
||||
|
||||
$currBalance = 0;
|
||||
$sql1 = "SELECT * FROM ".DAYBOOKMASTER." WHERE BranchCode = '$branch' AND ID = '$upFor'";
|
||||
$latestUpdate1 = $this->db->query($sql1);
|
||||
$latestUpdateDetails1 = $latestUpdate1->result();
|
||||
$currBalance = $latestUpdateDetails1[0]->Balance;
|
||||
|
||||
|
||||
$sql2 = "SELECT * FROM ".DAYBOOKMASTER." WHERE (BranchCode = '$branch' AND ID > '$upFor')
|
||||
ORDER BY ID ASC";
|
||||
$latestUpdate2 = $this->db->query($sql2);
|
||||
$latestUpdateDetails2 = $latestUpdate2->result();
|
||||
|
||||
foreach( $latestUpdateDetails2 as $clip){
|
||||
if($clip->Name == 'I002') {
|
||||
//Income
|
||||
$currBalance = $currBalance + $clip->Amount;
|
||||
}else if ($clip->Name == 'I001') {
|
||||
//Expense
|
||||
$currBalance = $currBalance - $clip->Amount;
|
||||
} else {
|
||||
}
|
||||
$updateSql = "UPDATE ".DAYBOOKMASTER." SET Balance ='$currBalance' WHERE ID = '$clip->ID'";
|
||||
$this->db->query($updateSql);
|
||||
}
|
||||
$result['updateDetailsStatus'] = true;
|
||||
$result['message'] = "Successfully Details Updated";
|
||||
} else {
|
||||
$result['updateDetailsStatus'] = false;
|
||||
$result['message'] = "Something went wrong.please try again";
|
||||
@ -187,11 +269,27 @@ class DayBook_model extends CI_Model
|
||||
// add dayBook
|
||||
public function add_dayBook($Arr)
|
||||
{
|
||||
$branch = $Arr['BranchCode'];
|
||||
$sql = "SELECT * FROM ".DAYBOOKMASTER." WHERE BranchCode = '$branch'
|
||||
ORDER BY CreatedOn DESC
|
||||
LIMIT 1";
|
||||
$latestUpdate = $this->db->query($sql);
|
||||
$latestUpdateDetails = $latestUpdate->result();
|
||||
$prevBalance = $latestUpdateDetails[0]->Balance;
|
||||
if($Arr['Name'] == 'I002') {
|
||||
//Income
|
||||
$Arr['Balance'] = $prevBalance + $Arr['Amount'];
|
||||
}else if ($Arr['Name'] == 'I001') {
|
||||
//Expense
|
||||
$Arr['Balance'] = $prevBalance - $Arr['Amount'];
|
||||
} else {
|
||||
$Arr['Balance'] = 0;
|
||||
}
|
||||
|
||||
$this->db->insert(DAYBOOKMASTER, $Arr);
|
||||
if ($this->db->affected_rows() == '1') {
|
||||
$result['addDayBookStatus'] = true;
|
||||
$result['message'] = "Successfully DayBook Details Added";
|
||||
|
||||
} else {
|
||||
$result['addDayBookStatus'] = false;
|
||||
$result['message'] = "Something went wrong.please try again";
|
||||
|
||||
@ -306,7 +306,7 @@ class Employee_model extends CI_Model
|
||||
} else if ($checkData == 'mobileNumber') {
|
||||
// check for mobile number
|
||||
$this->db->select('*');
|
||||
$this->db->from(STAFF);
|
||||
$this->db->from(LOGIN);
|
||||
$this->db->where('MobileNumber', $data);
|
||||
if ($this->db->get()->first_row()) {
|
||||
$result['existMobile'] = true;
|
||||
@ -415,7 +415,7 @@ class Employee_model extends CI_Model
|
||||
if ($checkFor == 'mobileNumber') {
|
||||
// check update for mobile number
|
||||
$this->db->select('*');
|
||||
$this->db->from(STAFF);
|
||||
$this->db->from(LOGIN);
|
||||
$this->db->where('MobileNumber', $datas);
|
||||
$this->db->where_not_in('StaffID', $exceptId);
|
||||
if ($this->db->get()->first_row()) {
|
||||
|
||||
@ -180,7 +180,9 @@ $scope.dayBookApprovalAccess = '';
|
||||
"description": "",
|
||||
"paidTo": "",
|
||||
"description_paid": "",
|
||||
"voucherNumber": ""
|
||||
"voucherNumber": "",
|
||||
"branch":"",
|
||||
"name":""
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +196,9 @@ $scope.dayBookApprovalAccess = '';
|
||||
"description": "",
|
||||
"paidTo": "",
|
||||
"description_paid": "",
|
||||
"voucherNumber": ""
|
||||
"voucherNumber": "",
|
||||
"branch": "",
|
||||
"name":""
|
||||
}
|
||||
|
||||
$scope.copyModel = function (p) {
|
||||
@ -209,8 +213,11 @@ $scope.dayBookApprovalAccess = '';
|
||||
"description": p.Description,
|
||||
"paidTo": p.PaidTo,
|
||||
"description_paid": p.PaidDescription,
|
||||
"voucherNumber": p.VoucherNumber
|
||||
"voucherNumber": p.VoucherNumber,
|
||||
"branch":p.BranchCode,
|
||||
"name": p.Name
|
||||
}
|
||||
// alert(JSON.stringify($scope.myModel));
|
||||
}
|
||||
|
||||
|
||||
@ -321,6 +328,7 @@ $scope.dayBookApprovalAccess = '';
|
||||
angular.element('.ng-invalid[name=' + firstError + ']').focus();
|
||||
// swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error");
|
||||
} else {
|
||||
|
||||
var formate = "dd-MM-yyyy";
|
||||
$scope.myModelAdd.date = $filter('date')(new Date($scope.myModelAdd.date), formate);
|
||||
$scope.myModelAdd.status = $scope.myModelAdd.name == 'I001' ? 'Pending' : 'Approved';
|
||||
@ -383,6 +391,7 @@ $scope.dayBookApprovalAccess = '';
|
||||
angular.element('.ng-invalid[name=' + firstError + ']').focus();
|
||||
// swal("The form cannot be submitted because it contains validation errors!", "Errors are marked with a red, dashed border!", "error");
|
||||
} else {
|
||||
// alert(JSON.stringify($scope.myModel));exit();
|
||||
var updateDayBookDetails = {
|
||||
method: 'POST',
|
||||
url: apiPoint.url + 'updateDayBookDetails/',
|
||||
@ -390,7 +399,7 @@ $scope.dayBookApprovalAccess = '';
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
data: {
|
||||
data: myModel,
|
||||
data: $scope.myModel,
|
||||
requestDetails: localDetails
|
||||
}
|
||||
};
|
||||
|
||||
@ -119,6 +119,9 @@
|
||||
<th>Amount
|
||||
<!--<span class="glyphicon sort-icon" ng-show="sortKey=='Amount'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>-->
|
||||
</th>
|
||||
<th>Balance
|
||||
<!--<span class="glyphicon sort-icon" ng-show="sortKey=='Amount'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>-->
|
||||
</th>
|
||||
|
||||
<th class="center" ng-click="sort('Status')">Status
|
||||
<span class="glyphicon sort-icon" ng-show="sortKey=='Status'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
|
||||
@ -137,6 +140,7 @@
|
||||
<span ng-if=" p.PaymentStatus == 1 ">{{p.TypeName}}</span>
|
||||
<span tooltip="Fees Updation" ng-if=" p.PaymentStatus == 0 " style="color:chocolate">{{p.TypeName}}</span></td>
|
||||
<td>{{p.Amount}}</td>
|
||||
<td>{{p.Balance}}</td>
|
||||
|
||||
<!--<td class="center" tooltip="{{p.Approval_Comments}}" ng-if="p.ListName == 'Income'">
|
||||
- </td>-->
|
||||
|
||||
Loading…
Reference in New Issue
Block a user