Merge branch '6-ajouter-la-page-de-l-inventaire' into 'master'

Corrections et améliorations de l'inventaire

See merge request color-recipes-explorer/frontend!11
This commit is contained in:
William Nolin 2021-03-20 21:05:35 +00:00
commit c56b96135c
7 changed files with 40 additions and 22 deletions

View File

@ -57,7 +57,7 @@
step="0.001"
[value]="getComputedQuantityRounded(mixMaterial)"
[disabled]="mixMaterial.material.materialType.usePercentages"
(change)="changeQuantity($event, mixMaterial)"/>
(keyup)="changeQuantity($event, mixMaterial)"/>
</mat-form-field>
</td>
<td mat-footer-cell *matFooterCellDef>
@ -69,7 +69,7 @@
min="0.001"
step="0.001"
[value]="round(getTotalQuantity())"
(change)="changeQuantity($event, null, true)"/>
(keyup)="changeQuantity($event, null, true)"/>
</mat-form-field>
</td>
</ng-container>

View File

@ -30,7 +30,7 @@
[units$]="units$"
(quantityChange)="changeQuantity($event)"
(locationChange)="changeMixLocation($event)"
(deduct)="deductMix($event)">
(deduct)="showDeductMixConfirm($event, deductConfirmBox)">
</cre-mixes-card>
</div>
@ -45,3 +45,9 @@
</div>
</div>
</div>
<cre-confirm-box
#deductConfirmBox
message="Voulez-vous vraiment déduire les quantités de ce mélange?"
(click)="deductMix()">
</cre-confirm-box>

View File

@ -7,6 +7,8 @@ import {Observable, Subject} from 'rxjs'
import {ErrorModel, ErrorService} from '../../../shared/service/error.service'
import {AlertService} from '../../../shared/service/alert.service'
import {GlobalAlertHandlerComponent} from '../../../shared/components/global-alert-handler/global-alert-handler.component'
import {InventoryService} from '../../../material/service/inventory.service'
import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confirm-box.component'
@Component({
selector: 'cre-explore',
@ -32,6 +34,7 @@ export class ExploreComponent extends ErrorHandlingComponent {
constructor(
private recipeService: RecipeService,
private inventoryService: InventoryService,
private alertService: AlertService,
errorService: ErrorService,
router: Router,
@ -94,15 +97,19 @@ export class ExploreComponent extends ErrorHandlingComponent {
)
}
deductMix(mixId: number) {
showDeductMixConfirm(mixId: number, confirmBox: ConfirmBoxComponent) {
this.deductedMixId = mixId
const firstMixMaterial = this.recipe.mixes.filter(m => m.id === mixId)[0].mixMaterials[0]
if (this.quantitiesChanges.has(mixId) && this.quantitiesChanges.get(mixId).has(firstMixMaterial.material.id)) {
confirmBox.show()
}
deductMix() {
const firstMixMaterial = this.recipe.mixes.filter(m => m.id === this.deductedMixId)[0].mixMaterials[0]
if (this.quantitiesChanges.has(this.deductedMixId) && this.quantitiesChanges.get(this.deductedMixId).has(firstMixMaterial.material.id)) {
const originalQuantity = firstMixMaterial.quantity
const currentQuantity = this.quantitiesChanges.get(mixId).get(firstMixMaterial.material.id)
this.subscribeDeductMix(this.recipeService.deductMixFromQuantities(mixId, originalQuantity, currentQuantity))
const currentQuantity = this.quantitiesChanges.get(this.deductedMixId).get(firstMixMaterial.material.id)
this.subscribeDeductMix(this.inventoryService.deductMixFromQuantities(this.deductedMixId, originalQuantity, currentQuantity))
} else {
this.subscribeDeductMix(this.recipeService.deductMix(mixId, 1))
this.subscribeDeductMix(this.inventoryService.deductMix(this.deductedMixId, 1))
}
}

View File

@ -67,13 +67,4 @@ export class RecipeService {
delete(id: number): Observable<void> {
return this.api.delete<void>(`/recipe/${id}`)
}
deductMixFromQuantities(mixId: number, originalQuantity: number, currentQuantity: number): Observable<MaterialQuantity[]> {
return this.deductMix(mixId, currentQuantity / originalQuantity)
}
deductMix(mixId: number, ratio: number): Observable<MaterialQuantity[]> {
const body = {id: mixId, ratio}
return this.api.put<MaterialQuantity[]>('/inventory/deduct/mix', body)
}
}

View File

@ -68,13 +68,16 @@
<ng-container matColumnDef="addQuantity">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell [class.disabled]="!canEditMaterial" *matCellDef="let material; let i = index">
<div *ngIf="(!hoveredMaterial && i === 0) || hoveredMaterial === material" class="input-group">
<div
[hidden]="!((!hoveredMaterial && i === 0) || (hoveredMaterial === material) || (selectedMaterial && selectedMaterial === material))"
class="input-group">
<input
#addQuantityInput
class="form-control"
type="number"
step="0.01"
placeholder="0"/>
placeholder="0"
(click)="selectedMaterial = material"/>
<div class="input-group-append">
<button
mat-flat-button

View File

@ -28,6 +28,7 @@ export class InventoryComponent extends ErrorHandlingComponent {
columns = ['name', 'materialType', 'quantity', 'addQuantity', 'lowQuantityIcon', 'simdutIcon', 'editButton', 'openSimdutButton']
hoveredMaterial: Material | null
selectedMaterial: Material | null
units = UNIT_MILLILITER
lowQuantityThreshold = 100 // TEMPORARY will be in the application settings
@ -115,6 +116,7 @@ export class InventoryComponent extends ErrorHandlingComponent {
materialQuantities => {
// Reset the input value
input.value = null
this.selectedMaterial = null
material.inventoryQuantity = parseInt(materialQuantities.filter(mq => mq.material === material.id)[0].quantity)
},

View File

@ -12,11 +12,20 @@ export class InventoryService {
}
add(material: number, quantity: number): Observable<MaterialQuantity[]> {
return this.api.put<MaterialQuantity[]>('/material/inventory/add', [{material, quantity}])
return this.api.put<MaterialQuantity[]>('/inventory/add', [{material, quantity}])
}
deductMixFromQuantities(mixId: number, originalQuantity: number, currentQuantity: number): Observable<MaterialQuantity[]> {
return this.deductMix(mixId, currentQuantity / originalQuantity)
}
deductMix(mixId: number, ratio: number): Observable<MaterialQuantity[]> {
const body = {id: mixId, ratio}
return this.api.put<MaterialQuantity[]>('/inventory/deduct/mix', body)
}
deduct(materialQuantities: [{material: number, quantity: number}]): Observable<MaterialQuantity[]> {
return this.api.put<MaterialQuantity[]>('/material/inventory/deduct', materialQuantities)
return this.api.put<MaterialQuantity[]>('/inventory/deduct', materialQuantities)
}
}