You've already forked openaccounting-web
forked from cybercinch/openaccounting-web
Merge pull request #4 from pnagurny/feature/delete-rec
Delete reconciliation
This commit is contained in:
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
<p>Copyright © 2018 Open Accounting, LLC<br>
|
<p>Copyright © 2019 Open Accounting, LLC<br>
|
||||||
<a href="/tou">Terms of Use</a> | <a href="/privacy-policy">Privacy Policy</a></p>
|
<a href="/tou">Terms of Use</a> | <a href="/privacy-policy">Privacy Policy</a></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ export class ReconcileModal {
|
|||||||
this.sessionService.setLoading(false);
|
this.sessionService.setLoading(false);
|
||||||
}, () => {
|
}, () => {
|
||||||
this.sessionService.setLoading(false);
|
this.sessionService.setLoading(false);
|
||||||
this.activeModal.close();
|
this.activeModal.close(txs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,11 +52,27 @@
|
|||||||
<div class="section">
|
<div class="section">
|
||||||
<h2>Past Reconciliations</h2>
|
<h2>Past Reconciliations</h2>
|
||||||
|
|
||||||
<div *ngFor="let rec of pastReconciliations">
|
<div *ngFor="let rec of pastReconciliations; index as i">
|
||||||
Period: {{rec.startDate | date:"M/d/y"}} - {{rec.endDate | date:"M/d/y"}}<br>
|
Period: {{rec.startDate | date:"M/d/y"}} - {{rec.endDate | date:"M/d/y"}}<br>
|
||||||
Beginning Balance: {{rec.startBalance | currencyFormat:account.precision:account.currency}}<br>
|
Beginning Balance: {{rec.startBalance | currencyFormat:account.precision:account.currency}}<br>
|
||||||
Ending Balance: {{rec.endBalance | currencyFormat:account.precision:account.currency}}<br>
|
Ending Balance: {{rec.endBalance | currencyFormat:account.precision:account.currency}}<br>
|
||||||
|
<a *ngIf="i === 0" [routerLink]="" (click)="delete()">Delete</a>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ng-template #confirmDeleteModal let-c="close" let-d="dismiss">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h4 class="modal-title">Confirm delete</h4>
|
||||||
|
<button type="button" class="close" aria-label="Close" (click)="d()">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>Are you sure you want to delete this reconciliation?</p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" (click)="d()">Cancel</button>
|
||||||
|
<button type="button" class="btn btn-primary" (click)="c()">Delete</button>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, ViewChild, ElementRef } from '@angular/core';
|
||||||
import { Logger } from '../core/logger';
|
import { Logger } from '../core/logger';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import {
|
import {
|
||||||
@@ -19,6 +19,10 @@ import { Util } from '../shared/util';
|
|||||||
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
|
import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap';
|
||||||
import { ReconcileModal } from './reconcile-modal';
|
import { ReconcileModal } from './reconcile-modal';
|
||||||
import { Reconciliation } from './reconciliation';
|
import { Reconciliation } from './reconciliation';
|
||||||
|
import { SessionService } from '../core/session.service';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
import 'rxjs/add/observable/from';
|
||||||
|
import 'rxjs/add/operator/mergeMap';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-reconcile',
|
selector: 'app-reconcile',
|
||||||
@@ -34,6 +38,7 @@ export class ReconcilePage {
|
|||||||
public unreconciledTxs: Transaction[];
|
public unreconciledTxs: Transaction[];
|
||||||
public error: AppError;
|
public error: AppError;
|
||||||
private accountTree: AccountTree;
|
private accountTree: AccountTree;
|
||||||
|
@ViewChild('confirmDeleteModal') confirmDeleteModal: ElementRef;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private router: Router,
|
private router: Router,
|
||||||
@@ -42,7 +47,8 @@ export class ReconcilePage {
|
|||||||
private orgService: OrgService,
|
private orgService: OrgService,
|
||||||
private txService: TransactionService,
|
private txService: TransactionService,
|
||||||
private fb: FormBuilder,
|
private fb: FormBuilder,
|
||||||
private modalService: NgbModal) {
|
private modalService: NgbModal,
|
||||||
|
private sessionService: SessionService) {
|
||||||
|
|
||||||
let org = this.orgService.getCurrentOrg();
|
let org = this.orgService.getCurrentOrg();
|
||||||
this.accountForm = fb.group({
|
this.accountForm = fb.group({
|
||||||
@@ -90,8 +96,10 @@ export class ReconcilePage {
|
|||||||
|
|
||||||
modal.componentInstance.setData(this.account, rec, this.unreconciledTxs);
|
modal.componentInstance.setData(this.account, rec, this.unreconciledTxs);
|
||||||
|
|
||||||
modal.result.then((result) => {
|
modal.result.then((txs) => {
|
||||||
this.log.debug('reconcile modal save');
|
this.log.debug('reconcile modal save');
|
||||||
|
rec.txs = txs;
|
||||||
|
|
||||||
this.pastReconciliations.unshift(rec);
|
this.pastReconciliations.unshift(rec);
|
||||||
|
|
||||||
this.newReconcile.patchValue(
|
this.newReconcile.patchValue(
|
||||||
@@ -170,6 +178,8 @@ export class ReconcilePage {
|
|||||||
|
|
||||||
let r = reconcileMap[endDate.getTime()];
|
let r = reconcileMap[endDate.getTime()];
|
||||||
|
|
||||||
|
r.txs.push(tx);
|
||||||
|
|
||||||
if(this.account.debitBalance) {
|
if(this.account.debitBalance) {
|
||||||
r.net += split.amount;
|
r.net += split.amount;
|
||||||
} else {
|
} else {
|
||||||
@@ -223,4 +233,61 @@ export class ReconcilePage {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete() {
|
||||||
|
this.modalService.open(this.confirmDeleteModal).result.then((result) => {
|
||||||
|
this.sessionService.setLoading(true);
|
||||||
|
|
||||||
|
let rec = this.pastReconciliations[0];
|
||||||
|
|
||||||
|
Observable.from(rec.txs).mergeMap(tx => {
|
||||||
|
let oldId = tx.id;
|
||||||
|
tx.id = Util.newGuid();
|
||||||
|
|
||||||
|
let data = tx.getData();
|
||||||
|
|
||||||
|
let newSplits = {};
|
||||||
|
|
||||||
|
for(let splitId in data.reconciledSplits) {
|
||||||
|
if(tx.splits[splitId].accountId !== this.account.id) {
|
||||||
|
newSplits[splitId] = tx.splits[splitId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.reconciledSplits = newSplits;
|
||||||
|
|
||||||
|
tx.setData(data);
|
||||||
|
|
||||||
|
return this.txService.putTransaction(oldId, tx);
|
||||||
|
}, 8).subscribe(tx => {
|
||||||
|
this.log.debug('Saved tx ' + tx.id);
|
||||||
|
}, err => {
|
||||||
|
this.error = err;
|
||||||
|
this.sessionService.setLoading(false);
|
||||||
|
}, () => {
|
||||||
|
this.pastReconciliations.shift();
|
||||||
|
let lastRec = this.pastReconciliations[0];
|
||||||
|
|
||||||
|
if(lastRec) {
|
||||||
|
this.newReconcile.patchValue(
|
||||||
|
{
|
||||||
|
startDate: Util.getLocalDateString(lastRec.endDate),
|
||||||
|
startBalance: lastRec.endBalance / Math.pow(10, this.account.precision)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.newReconcile.patchValue(
|
||||||
|
{
|
||||||
|
startDate: null,
|
||||||
|
startBalance: 0
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sessionService.setLoading(false);
|
||||||
|
});
|
||||||
|
}, (reason) => {
|
||||||
|
this.log.debug('cancel delete');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import { Transaction } from '../shared/transaction';
|
||||||
|
|
||||||
export class Reconciliation {
|
export class Reconciliation {
|
||||||
startDate: Date;
|
startDate: Date;
|
||||||
startBalance: number;
|
startBalance: number;
|
||||||
endDate: Date;
|
endDate: Date;
|
||||||
endBalance: number;
|
endBalance: number;
|
||||||
net: number;
|
net: number;
|
||||||
|
txs: Transaction[] = [];
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user