import { Entity } from './entity'; import { Movimentacao } from './movimentacao'; import { Terminal } from './terminal'; import { Serializable } from '../interfaces/serializable'; export class Caixa extends Entity { public terminal: Terminal; public data_abertura: string; public data_fechamento: string; public status: string; public _sync_local: boolean = false; public movimentacoes: Array; constructor(json?: any, generateId?: boolean) { super(json, generateId); json = json || {}; this.movimentacoes = json.movimentacoes || []; this._sync_local = json._sync_local || false; this.terminal = json.terminal && new Terminal(json.terminal); this.status = json.status || 'fechado'; this.data_abertura = json.data_abertura; this.data_fechamento = json.data_fechamento; } public abrir(): void { this.status = 'aberto'; this.data_abertura = new Date().toISOString(); this.update(); } public fechar(): void { this.status = 'fechado'; this.data_fechamento = new Date().toISOString(); this.update(); } public addMovimentacao(movimentacao: Movimentacao): void { this.movimentacoes.push(movimentacao); this.update(); } public setMovimentacoes(movimentacoes: Array): void { this.movimentacoes = movimentacoes; this.update(); } public toJson() { return Object.assign({}, this, super.toJson()); } }