Skip to content

Commit

Permalink
fix cost saving
Browse files Browse the repository at this point in the history
  • Loading branch information
LeosPrograms committed Apr 15, 2024
1 parent 6194c99 commit d135fd9
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 42 deletions.
13 changes: 10 additions & 3 deletions ui/src/lib/CommitmentModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
let id = e.target.value
console.log(id)
newCommitment.receiverId = id
console.log(newCommitment)
}}
>
{#each agents as agent}
Expand Down Expand Up @@ -475,15 +476,21 @@
// console.log(JSON.stringify(allColumns[commitmentModalColumn][commitmentModalProcess][commitmentModalSide][0].provider.name))

// let allColumnsCopy = [...allColumns]

// plan_created = true;
let updatedCommitment = {...selectedCommitment}
if (!selectedCommitment.provider) {
if (!selectedCommitment.providerId) {
updatedCommitment.providerId = newCommitment.providerId
}
if (!selectedCommitment.receiver) {
if (!selectedCommitment.provider) {
updatedCommitment.provider = newCommitment.provider
}
if (!selectedCommitment.receiverId) {
updatedCommitment.receiverId = newCommitment.receiverId
}
if (!selectedCommitment.receiver) {
updatedCommitment.receiver = newCommitment.receiver
}
if (!selectedCommitment.resourceConformsTo) {
updatedCommitment.resourceConformsTo = newCommitment.resourceConformsTo
}
Expand Down
30 changes: 22 additions & 8 deletions ui/src/lib/PlanModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,20 @@
}
async function saveOrUpdateCommitment(commitment: CommitmentUpdateParams) {
console.log("save or updated commitment", commitment.resourceConformsTo.name, resourceSpecifications)
console.log("save or updated commitment", commitment.resourceConformsTo?.name, resourceSpecifications)
let unitId = commitment.resourceQuantity?.hasUnitId ? commitment.resourceQuantity?.hasUnitId : commitment.resourceQuantity?.hasUnit?.id
if (unitId === undefined) {
unitId = units.find((u) => u.label === commitment.resourceQuantity?.hasUnit?.label)?.id
}
let o: CommitmentCreateParams = {
plannedWithin: commitment.plannedWithin,
finished: commitment.finished,
note: commitment.note,
hasBeginning: new Date(Date.now()),
resourceConformsTo: resourceSpecifications.find((rs) => rs.name === commitment.resourceConformsTo.name).id,
resourceConformsTo: resourceSpecifications.find((rs) => rs.name === commitment.resourceConformsTo?.name).id,
resourceQuantity: {
hasNumericalValue: Number(commitment?.resourceQuantity?.hasNumericalValue),
hasUnit: commitment?.resourceQuantity?.hasUnitId ? commitment?.resourceQuantity?.hasUnitId : units.find((u) => u.label === commitment?.resourceQuantity?.hasUnit?.label).id,
hasUnit: unitId
},
}
console.log("commitment check unit id", commitment)
Expand Down Expand Up @@ -362,7 +366,7 @@
})
console.log("added commitment", res)
// commitmentsSavedCount++
await new Promise(r => setTimeout(r, 100));
// await new Promise(r => setTimeout(r, 100));
} catch (e) {
console.log(e)
error = e
Expand Down Expand Up @@ -474,6 +478,11 @@
resourceConformsTo: dollars,
resourceQuantity: {
hasNumericalValue: Number(c.agreement.commitment.resourceQuantity.hasNumericalValue),
hasUnitId: dollars.defaultUnitOfResource.id,
hasUnit: {
id: dollars.defaultUnitOfResource.id,
label: dollars.defaultUnitOfResource.label
}
},
finished: false,
note: c.agreement.commitment.note,
Expand Down Expand Up @@ -511,7 +520,7 @@
console.log("trying to save payment commitment", payment)
let paymentCommitment = await saveOrUpdateCommitment(payment)
commitmentsSavedCount = commitmentsSavedCount + 1
await new Promise(r => setTimeout(r, 1000));
// await new Promise(r => setTimeout(r, 1000));
console.log("payment commitment 3", paymentCommitment)
} catch (e) {
console.log("could not add payment commitment", e)
Expand All @@ -537,17 +546,22 @@
// TEMPORARY find unit id
if (c.revisionId == undefined) {
console.log("finding unit id", c.resourceQuantity)
let unitId = c.resourceQuantity?.hasUnitId ? c.resourceQuantity?.hasUnitId : c.resourceQuantity?.hasUnit?.id
if (unitId === undefined) {
unitId = units.find((u) => u.label === c.resourceQuantity?.hasUnit?.label)?.id
}
c = {
...c,
resourceQuantity: {
...c.resourceQuantity,
// ...c.resourceQuantity,
...((({ hasUnitId, ...o }) => o)(c.resourceQuantity)),
hasUnit: {
...c.resourceQuantity.hasUnit,
// id: c.resourceQuantity.hasUnit.id
id: c.resourceQuantity?.hasUnitId ? c?.resourceQuantity?.hasUnitId : units.find((u) => u.label === c?.resourceQuantity?.hasUnit?.label).id,
id: unitId
}
}
}
console.log("HERE IS THE C", c)
// c.resourceQuantity.hasUnit.id = units.find((u) => u.label === c.resourceQuantity.hasUnit.label).id
}
// UNIT ID FIND ENDS
Expand Down
12 changes: 4 additions & 8 deletions ui/src/lib/RequestModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@
unitBased: true,
note: "shearing end of May"
}
createRequest(proposal, currentIntent, currentReciprocalIntent)
await createRequest(proposal, currentIntent, currentReciprocalIntent)
dispatch("submit");
submitting = false;
open = false;
Expand Down Expand Up @@ -305,7 +305,7 @@
From: "opacity-100 translate-y-0 sm:scale-100"
To: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
-->
{#if !submitting}
<!-- {#if !submitting} -->
<div
class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6"
class:hidden={!open}
Expand Down Expand Up @@ -500,20 +500,16 @@
>
</div>
</div>
{:else}
<!-- {:else}
<div
class="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full"
class:hidden={!submitting}
>
<div class="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
<div class="sm:flex sm:items-start">
<!-- <div
class="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-green-100 sm:mx-0 sm:h-10 sm:w-10"
> -->
<svg width="50" height="50" viewBox="0 0 50 50">
<circle cx="25" cy="25" r="20" fill="none" stroke-width="5" stroke="rgb(99,102,241)" stroke-dasharray="31.415, 31.415" />
</svg>
<!-- </div> -->
<div class="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
<h3
class="text-lg leading-6 font-medium text-gray-900"
Expand All @@ -530,7 +526,7 @@
</div>
</div>
</div>
{/if}
{/if} -->
</div>
</div>
</div>
19 changes: 12 additions & 7 deletions ui/src/routes/plans/new/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
committedOutputs: process.committedOutputs.map(output => {
const output_exchange = findExchange(output, process.based_on.name)
console.log("output_exchange", output_exchange)
// if (output_exchange) {
if (output_exchange) {
console.log("maybe making agreement 1", output_exchange)
const output_agreement = makeAgreement(output, output_exchange, offers)
console.log('output_agreement', output_agreement)
Expand All @@ -560,12 +560,13 @@
agreement: output_agreement
}
}
// }
}
return output
}),
committedInputs: process.committedInputs.map(input => {
// if there is no input, we don't need to make an agreement
const input_exchange = findExchange(input, process.based_on.name)
// if (input_exchange) {
if (input_exchange) {
console.log("maybe making agreement 2", input_exchange)
const input_agreement = makeAgreement(input, input_exchange, offers)
if (input_agreement) {
Expand All @@ -576,7 +577,7 @@
agreement: input_agreement
}
}
// }
}
return input
})
}
Expand Down Expand Up @@ -672,10 +673,12 @@
// .find(a_recipe => {
// if (based_on_name) {
// return a_recipe?.has_recipe_clause?.some(
// clause =>
// clause.resourceConformsTo.name ==
// clause => {
// console.log("stage", clause.stage?.name, based_on_name)
// return clause.resourceConformsTo.name ==
// commitment?.resourceConformsTo?.name &&
// clause.stage?.name == based_on_name
// }
// )
// } else {
// return a_recipe?.has_recipe_clause?.some(
Expand All @@ -687,6 +690,8 @@
// }
// })
// console.log(commitment, based_on_name, recipes, test)
// console.log("exchange test", test)
return recipes
Expand Down Expand Up @@ -717,7 +722,7 @@
// if (!reciprocal_clause) return
// let numerical_value = reciprocal_clause.resourceQuantity.hasNumericalValue
// let hasUnit = reciprocal_clause.resourceQuantity.hasUnit
let specific_provider = commitment.provider
let specific_provider = agents.find(it => it.id == commitment.providerId)
console.log("specific provider", specific_provider)
let numerical_value;
let hasUnit;
Expand Down
Loading

0 comments on commit d135fd9

Please sign in to comment.